導航:首頁 > 文件處理 > c程序如何打開同路徑文件夾

c程序如何打開同路徑文件夾

發布時間:2024-03-28 03:24:11

A. C語言怎麼讀取某一文件夾下的所有文件夾和文件

讀取的代碼方式如下:

intmain()

{

longfile;

struct_finddata_tfind;

_chdir("d:\");

if((file=_findfirst("*.*",&find))==-1L)

{

printf("空白! ");

exit(0);

}

printf("%s ",find.name);

while(_findnext(file,&find)==0)

{

printf("%s ",find.name);

}

_findclose(file);

return0;

}

B. 如何用C/C++語言實現執行一個程序和打開一個文件夾

//
這是我以前寫的一個,你參考參考
要用到windows
api
函數
#include
#include
#include
#define
len
1024
//
深度優先遞歸遍歷目錄中所有的文件
bool
directorylist(lpcstr
path)
{
win32_find_data
finddata;
handle
herror;
int
filecount
=
0;
char
filepathname[len];
//
構造路徑
char
fullpathname[len];
strcpy(filepathname,
path);
strcat(filepathname,
"\\*.*");
herror
=
findfirstfile(filepathname,
&finddata);
if
(herror
==
invalid_handle_value)
{
printf("搜索失敗!");
return
0;
}
while
(::findnextfile(herror,
&finddata))
{
//
過慮.和..
if
(strcmp(finddata.cfilename,
".")
==
0
||
strcmp(finddata.cfilename,
"..")
==
0
)
{
continue;
}
//
構造完整路徑
wsprintf(fullpathname,
"%s\\%s",
path,finddata.cfilename);
filecount++;
//
輸出本級的文件
printf("\n%d
%s
",
filecount,
fullpathname);
if
(finddata.dwfileattributes
&
file_attribute_directory)
{
printf("
");
directorylist(fullpathname);
}
}
return
0;
}
void
main()
{
directorylist("g:");
}

閱讀全文

與c程序如何打開同路徑文件夾相關的資料

熱點內容
個人信息處理者加密 瀏覽:777
著名的p字開頭的網站 瀏覽:420
大尺度bl電影有哪些 瀏覽:583
angelababy演的電影陳家溝 瀏覽:353
在線看日本片網站 瀏覽:584
風月小說by蘇他txt下載 瀏覽:990
韓國愛人是誰演的 瀏覽:731
主角把自己母親納入後宮的小說 瀏覽:46
啟示錄女主角真生孩子 瀏覽:834
在線看愛情動作電影 瀏覽:107
2020年韓國最好看的影視網站 瀏覽:72
穿越一女n夫的男權世界 瀏覽:309
看以前的電影都在哪裡看的 瀏覽:382
手機登錄問道雲伺服器超時 瀏覽:688
龍貓下載 ftp 瀏覽:287
伺服器如何載入插件 瀏覽:600
國產電影當中哪部片子出現老公是老婆奶的 瀏覽:516
男主姓顧女主設計師 瀏覽:113
小說主角葉凌天 瀏覽:146
可以在線看的小網站 瀏覽:53