導航:首頁 > 文件處理 > 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程序如何打開同路徑文件夾相關的資料

熱點內容
法國馬蹄鐵電影在線 瀏覽:263
中國大陸老動作全部電影 瀏覽:876
十大封禁愛情電影觀看 瀏覽:489
推薦血戀同級別的電影 瀏覽:117
男主意外和女主有孩子 瀏覽:616
先收女後收母的小說 瀏覽:998
無卡頓在線視頻 瀏覽:128
在網址前面加什麼不需要vip 瀏覽:516
我叫王剛電影的女孩是誰 瀏覽:66
韓國倫理女演員李彩 瀏覽:879
虎丘網格化管理app在哪裡下載 瀏覽:191
一個男孩在庄園里的電影 瀏覽:462
程序員技術做到極限 瀏覽:864
主角可以回到抗戰賣軍火 瀏覽:956
會計雲課堂文件夾是哪個 瀏覽:909
日本推理片和歐美推理片哪個好 瀏覽:446
編程跳轉id指令怎麼用 瀏覽:960
蒼白貧血作品集txt 瀏覽:304
紅羊打真軍電影有哪些 瀏覽:88
海外懸疑電影推薦 瀏覽:270