導航:首頁 > 文件教程 > c讀取文件夾下所有文件

c讀取文件夾下所有文件

發布時間:2025-01-19 01:39:40

❶ 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;

}

❷ C# 遍歷文件夾下所有子文件夾中的文件,得到文件名

假設a文件夾在F盤下,代碼如下。將文件名輸出到一個ListBox中
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
DirectoryInfo theFolder = new DirectoryInfo(@"F:\a\");
DirectoryInfo[] dirInfo = theFolder.GetDirectories();
//遍歷文件夾
foreach (DirectoryInfo NextFolder in dirInfo)
{
// this.listBox1.Items.Add(NextFolder.Name);
FileInfo[] fileInfo = NextFolder.GetFiles();
foreach (FileInfo NextFile in fileInfo) //遍歷文件
this.listBox2.Items.Add(NextFile.Name);
}

}
}
}

❸ C語言如何實現遍歷文件夾下的所有txt文件並在文件中搜索字元串

用 FINDFile和FindNextFile可以遍歷整個文件夾,然後取出文件名判斷是否txt,再打開文件讀取內容進行查找。

❹ 如何獲得某一文件夾下文件列表(C語言)

我也有同樣來的問題。
到網上查,源感覺實現較復雜。
最後用的是c語言調用cmd
生成文件列表文件,再用c語言去讀取那個文件。進行字元串處理。
c語言調用cmd 為 system(「cmd命令」);

比如:
#include <stdio.h>
#include <dos.h>
int main()
{
system("dir /s /b > filelist.txt");/*這是全部文件,包括子目錄*/
system("dir *.txt /b > filelist2.txt"); /*當前目錄下的所有txt文件,不包括子目錄*/
/*然後*/
sleep(100);
FILE * ptrin = fopen("filelist","r");/*讀取並進行處理*/
/*處理*/
/*關閉文件flose(ptrin);*/
return 0;
}

希望有誰有更好的辦法。

❺ C++下讀取某一文件夾內所有txt文件,並把所有的文件名存在字元串數組中

CString strfilepatch = _T("C:\Users\Public\TEMP.txt");
FILE *pFile = fopen(strfilepatch,"rb"); //打開
if (NULL == pFile)
{
AfxMessageBox(_T("文件打開失敗"));
return;
}

unsigned char *pbuff;
UINT FileLen(0); // 文件長度
fseek(pFile,0,SEEK_END);
FileLen = ftell(pFile);
fseek(pFile,0,SEEK_SET);
pbuff = (unsigned char *)malloc(FileLen);
fread(pbuff,1,FileLen,pFile);

// 保存到數組Data中
unsigned char Data[262144];
for (UINT Count = 0; Count < FileLen ; Count++)
{
Data[Count] = *pbuff;
pbuff++;

}

CString szGetName = _T("C:\Users\Public\TEMP_1.txt"); //
wsprintf(mess, _T("%s"),szGetName);
FILE* pf = fopen(mess, "ab");
if( pf != NULL )
{
fwrite(DataAll, 1, filelencount-6, pf);
fclose(pf);
pf = NULL;
}

❻ 在windows下 怎麼用c語言遍歷文件夾要用純c的

什麼叫純C?
用C語言遍歷文件肯定需要用到函數,標准C下貌似沒有這個函數內,但容是使用VC的函數庫可能可以實現,如果實在不行可以用第三方函數庫,,,還不行的話用system("command");引用dos命令可以遍歷,

閱讀全文

與c讀取文件夾下所有文件相關的資料

熱點內容
有哪些app能借出5000 瀏覽:250
編程語言哪個發展好 瀏覽:974
刪除xp密碼 瀏覽:974
手機怎麼在word製作作業文件 瀏覽:489
工行銀行卡安全升級 瀏覽:807
桌面放的文件找不到 瀏覽:922
買學生票用什麼app 瀏覽:590
共建共享網路平台 瀏覽:39
js傳值到超鏈接裡面 瀏覽:608
編程中的w和h是什麼 瀏覽:313
資料庫切了什麼意思 瀏覽:213
如何登錄極路由器設置密碼 瀏覽:522
jsp用戶登陸密碼加密源代碼 瀏覽:629
everfilter使用教程 瀏覽:768
作業票文件名稱是什麼 瀏覽:463
私密文件忘記密碼 瀏覽:686
藏文軟體app怎麼可以下載 瀏覽:960
鍵盤文件名 瀏覽:538
電腦自帶驅動在那個文件夾 瀏覽:531
c窗體讀取文件夾 瀏覽:965

友情鏈接