導航:首頁 > 文件教程 > 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語言監聽文件夾相關的資料

熱點內容
炒股軟體指標編程用的是什麼語言 瀏覽:261
三星美版s6怎麼開網路 瀏覽:197
數據線什麼樣的好 瀏覽:138
怎麼根據ipv4地址算網路地址 瀏覽:48
概率演算法程序集pdf 瀏覽:457
遂平app商城有哪些 瀏覽:693
有哪些語言支持函數式編程範式 瀏覽:960
iphone6plus怎麼充電 瀏覽:939
批量導入word文件製作ppt 瀏覽:676
蘋果6如何跳過id激活 瀏覽:899
文件夾優酷中緩存的視頻找不到 瀏覽:685
成都騰進網路技術有限公司 瀏覽:549
電腦保存文件怎麼發到qq 瀏覽:556
寶寶文件夾圖片 瀏覽:516
蘋果電腦如何剪切文件夾 瀏覽:183
蘋果電腦怎麼拷貝excel文件 瀏覽:260
cf狙擊準星工具 瀏覽:27
西門子數控編程r11r25是什麼意思 瀏覽:574
iphone6怎麼刪除聯系人 瀏覽:643
ipad4刷安卓系統 瀏覽:463

友情鏈接