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

熱點內容
vb組態軟體源碼 瀏覽:698
加密蚊帳防蚊門簾 瀏覽:828
vs2010多線程編程 瀏覽:214
新股上市指標源碼 瀏覽:698
c語言51單片機教程 瀏覽:554
app中的hd是什麼意思 瀏覽:279
手機什麼解壓器最好 瀏覽:49
什麼是適合自己的app 瀏覽:451
雲伺服器怎麼補漏洞 瀏覽:176
如何看自己的安卓是什麼等級 瀏覽:633
被丁磊挖走的程序員 瀏覽:19
gsk980ta編程 瀏覽:507
單片機離線 瀏覽:84
解壓助眠敲擊外國長指甲 瀏覽:421
3次元編程 瀏覽:803
夫妻傳送英文命令 瀏覽:316
程序員題代做 瀏覽:950
戴爾伺服器怎麼擴大內存 瀏覽:641
解壓包密碼消失 瀏覽:135
昆侖通態觸摸屏用戶窗加密 瀏覽:564