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

熱點內容
pdf文件名怎麼換顏色 瀏覽:868
核桃編程如何退錢 瀏覽:17
如何查看預約app 瀏覽:774
數控哪個編程軟體速度最快 瀏覽:135
qq表情白眼是哪個 瀏覽:965
shell循環文件名 瀏覽:602
照片3d建模源代碼 瀏覽:434
西安iPhone6升級內存 瀏覽:84
小學生的編程的課是學什麼的 瀏覽:114
就業下載什麼app 瀏覽:191
個人配置文件重定向到D盤 瀏覽:22
js屏幕寬度 瀏覽:312
sql查找某列重復資料庫 瀏覽:48
智行火車票用微信支付 瀏覽:262
網路定價過程哪些內容發生變化 瀏覽:200
dubbo服務提供者的配置文件 瀏覽:182
win8系統如何壓縮文件 瀏覽:875
網站怎麼上傳代碼 瀏覽:4
java日誌的好處 瀏覽:103
武漢奇米網路怎麼樣 瀏覽:689

友情鏈接