检查目录并获取文件名 [英] Check directory and take filename

查看:62
本文介绍了检查目录并获取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要一个逻辑来检查文件的目录,如果文件存在我需要将文件名存储到变量



例如: -



i我有一个名为test的目录,最初它是空的,我需要不断检查这个目录中的文件,如果目录中有任何文件,例如:如果它包含name.txt

文件

i需要将此名称存储到如下变量



char * buff;

buff = name.txt;






任何plz都可以提出任何想法,我有一个逻辑检查目录,但我知道如何取一个文件名并将其存储在变量中



谢谢

shan

Hi all,

I need a logic for checking the directory for a file if a file exists i need to store the file name to a variable

for example:-

i am having a directory called "test", initially it is empty, i need to continuously check this directory for a file if any file is present in the directory for eg: if it contains "name.txt"
file
i need to store this name to a variable like below

char *buff;
buff = name.txt;



can any plz suggest any idea, i have a logic for checking the directory but i do know how to take a filename and to store that in a variable

Thanks
shan

推荐答案

线程 [ ^ ]包含一些专门针对C(而不是C ++)的想法
This thread[^] contains some ideas specifically for C (not C++)


使用< a href =http://www.linuxjournal.com/article/8478> inotify API [ ^ ]以持续监视目录。 inotify事件结构包含一个文件名,您可以在分配足够大的缓冲区后使用 strncpy()将其复制到您自己的变量。
Use the inotify API[^] to continuously monitor the directory. The inotify event structure contains a file name you can copy to your own variable with strncpy() after allocating a sufficiently large buffer.


这篇关于检查目录并获取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆