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

熱點內容
論文app怎麼用 瀏覽:466
開源文件伺服器加密 瀏覽:588
哈利波特游戲選什麼伺服器 瀏覽:424
雲伺服器怎樣格式化 瀏覽:16
框架柱頂部箍筋加密區規范 瀏覽:169
pythonjson文件讀取 瀏覽:105
夢幻西遊源碼架設 瀏覽:123
抽煙有解壓效果嗎 瀏覽:827
由於加密數據錯誤這個會話將結束 瀏覽:832
javaproject運行 瀏覽:255
0經驗轉行單片機 瀏覽:637
什麼叫解壓縮下載的文件 瀏覽:862
什麼牌子的手機加密狗好用 瀏覽:536
程序員編程學習筆記 瀏覽:864
吃雞亞服怎麼選擇不了伺服器 瀏覽:658
數控設備宏程序編程 瀏覽:840
高速銑編程培訓 瀏覽:650
天正改命令 瀏覽:773
路由器域名伺服器地址怎麼填 瀏覽:88
外掛編譯環境用什麼 瀏覽:216