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

熱點內容
小書亭下載的文件在哪手機文件夾 瀏覽:173
交叉編譯器編譯單個c文件 瀏覽:509
代理伺服器地址列表吧 瀏覽:928
java列出所有文件 瀏覽:866
壓縮包看圖軟體 瀏覽:187
sqlite在android中的應用 瀏覽:657
一本通pdf 瀏覽:911
2021免費的編程軟體 瀏覽:124
項目編譯後瀏覽器不對應刷新 瀏覽:565
三星升級android60 瀏覽:293
粘土的壓縮模量 瀏覽:116
美國程序員生活 瀏覽:220
51單片機摘要 瀏覽:406
英語經典pdf下載 瀏覽:320
大學文件夾怎麼刪除 瀏覽:671
linux科研軟體 瀏覽:556
ue4打包編譯著色器 瀏覽:778
雲伺服器可以在手機上登錄嗎 瀏覽:678
網游腳本為什麼要連接伺服器 瀏覽:11
程序員發展路線圖 瀏覽:320