导航:首页 > 文件教程 > c语言监听文件夹

c语言监听文件夹

发布时间:2024-04-17 05:02:47

1. c语言中指定路径怎么检测是否存在 一个文件

这个简单啦,用
CreateDirectory
函数创建那个目录,如果目录已经存在了,那么创建必然失败

2. windowXP环境下如何用C语言判断是文件还是文件夹

1 //头文件
2 #include "stdio.h"
3 #include "stdlib.h"
4 #include <sys/stat.h>
5 //代码
6 int main()
7 {
8 char* fileName = "aa.txt";
9 struct _stat buf;
10 int result;
11 result = _stat( fileName, &buf );
12 if(_S_IFDIR & buf.st_mode){
13 printf("folder\n");
14 }else if(_S_IFREG & buf.st_mode){
15 printf("file\n");
16 }
17
18 return 0;
19 }

3. c语言怎么打开一个文件夹

在C语言中,对文件夹的操作,专业的说法称为"切换路径/目录",而不是"打开",因为文件夹,并不是一个"真正的文件",而只是一个访问文件的目录.x0dx0ax0dx0a用C语言中的函数chdir,也就是change directory x0dx0aint chdir(char *path) x0dx0a-- 使指定的目录path变成当前的工作目录,之后所有的文件操作都是该目录下.x0dx0ax0dx0a比如,想切换到f盘test目录下可以这样:x0dx0a chdir("f:\\test "); x0dx0a返回0表示切换成功,否则,表示失败.

4. 如何用C语言判断文件夹内是否有文件夹或文件

举例来说:FILE*fp=fopen("dict.txt","r");charbuf[1024];if(fp!=(FILE*)NULL){while(fgets(buf,sizeof(buf),fp))//从文件中读入一行字符串,保存在buf中,直到读完所有字符串{//处理读入的字符串buf}fclose(fp);}

5. C语言:如何得到指定地址的文件夹中所有文件的文件名和其修改时间 包括子文件内的

//获取指定目录下的所有文件列表 author:wangchangshaui jlu
char** getFileNameArray(const char *path, int* fileCount)
{
int count = 0;
char **fileNameList = NULL;
struct dirent* ent = NULL;
DIR *pDir;
char dir[512];
struct stat statbuf;

//打开目录
if ((pDir = opendir(path)) == NULL)
{
myLog("Cannot open directory:%s\n", path);
return NULL;
}
//读取目录
while ((ent = readdir(pDir)) != NULL)
{ //统计当前文件夹下有多少文件(不包括文件夹)
//得到读取文件的绝对路径名
snprintf(dir, 512, "%s/%s", path, ent->d_name);
//得到文件信息
lstat(dir, &statbuf);
//判断是目录还是文件
if (!S_ISDIR(statbuf.st_mode))
{
count++;
}
} //while
//关闭目录
closedir(pDir);
// myLog("共%d个文件\n", count);

//开辟字符指针数组,用于下一步的开辟容纳文件名字符串的空间
if ((fileNameList = (char**) myMalloc(sizeof(char*) * count)) == NULL)
{
myLog("Malloc heap failed!\n");
return NULL;
}

//打开目录
if ((pDir = opendir(path)) == NULL)
{
myLog("Cannot open directory:%s\n", path);
return NULL;
}
//读取目录
int i;
for (i = 0; (ent = readdir(pDir)) != NULL && i < count;)
{
if (strlen(ent->d_name) <= 0)
{
continue;
}
//得到读取文件的绝对路径名
snprintf(dir, 512, "%s/%s", path, ent->d_name);
//得到文件信息
lstat(dir, &statbuf);
//判断是目录还是文件
if (!S_ISDIR(statbuf.st_mode))
{
if ((fileNameList[i] = (char*) myMalloc(strlen(ent->d_name) + 1))
== NULL)
{
myLog("Malloc heap failed!\n");
return NULL;
}
memset(fileNameList[i], 0, strlen(ent->d_name) + 1);
strcpy(fileNameList[i], ent->d_name);
myLog("第%d个文件:%s\n", i, ent->d_name);
i++;
}
} //for
//关闭目录
closedir(pDir);

*fileCount = count;
return fileNameList;
}

阅读全文

与c语言监听文件夹相关的资料

热点内容
现实中的数据说明什么 浏览:15
三星q330拆机教程 浏览:597
pmp转换器找不到文件 浏览:8
小米WiFiapp不能登录 浏览:736
哪个app能刷公考题 浏览:803
dbca创建数据库 浏览:335
iphone6面部识别破解 浏览:776
笔记本电脑找不到uv保存的文件 浏览:163
高端手机网站怎么做 浏览:91
ps教程百度云盘 浏览:965
编程等级测评合格后证书怎么寄 浏览:781
抖音显示网络错误怎么办华为手机 浏览:778
spss如何跑数据 浏览:716
找不到启动的文件 浏览:38
移动歌曲怎么找不到指定文件 浏览:43
javaweb选课系统 浏览:182
linux清空缓冲区 浏览:478
如何将png文件名导入excel 浏览:660
吉他谱网站哪个好 浏览:205
返校win10能玩么 浏览:153

友情链接