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

熱點內容
python生成訂單數據 瀏覽:358
安卓手機正面視頻怎麼調整為左邊 瀏覽:920
java定義整數 瀏覽:371
怎麼添加數據透視表命令 瀏覽:799
hk4100f與單片機連接 瀏覽:861
門禁鑰匙加密可以復制嗎 瀏覽:194
單片機ad采樣交流信號 瀏覽:161
龍門銑外圓編程 瀏覽:518
gal編程工具 瀏覽:401
浙大翁愷老師用的什麼編譯器 瀏覽:592
gs5發動機壓縮比 瀏覽:716
稅控盤插上顯示未檢測加密盤 瀏覽:305
怎麼潛移默化的命令一個人 瀏覽:115
解壓筆爛了怎麼補 瀏覽:683
db什麼文件夾 瀏覽:868
寶駿730熱車壓縮機不工作 瀏覽:505
伺服器崩潰怎麼登錄 瀏覽:899
怎麼看伺服器是多少c 瀏覽:670
趣智校園app怎麼使用 瀏覽:155
樂家達要下什麼app 瀏覽:346