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

熱點內容
安卓tcpsocketsend 瀏覽:527
在哪裡下載輕草app 瀏覽:673
java文件名下載 瀏覽:335
深圳華強北蘋果7報價 瀏覽:337
i9300基帶文件 瀏覽:536
18款寶來加裝霧燈如何編程 瀏覽:894
女生送包了兩層紙的蘋果 瀏覽:186
a790e線刷教程 瀏覽:962
win10系統如何復制Pdf文件 瀏覽:800
js滑鼠移動圖顯示數據 瀏覽:203
微信網名帶念字 瀏覽:161
提取一個文件夾里的所有圖片 瀏覽:198
三星s5自帶文件管理器 瀏覽:356
如何將文檔數據按規定排序 瀏覽:660
word中的文件如何重命名 瀏覽:272
新基建中的數據中心是指什麼 瀏覽:728
pdf掃描文件插入圖片大小 瀏覽:362
java500錯誤原因 瀏覽:905
sx1278代碼 瀏覽:729
調試配置文件 瀏覽:780

友情鏈接