當前位置:首頁 » 文件管理 » c枚舉文件夾中的文件夾

c枚舉文件夾中的文件夾

發布時間: 2023-01-29 19:42:17

⑴ 如何枚舉目錄文件夾裡面文件名

枚舉文件 .版本 2.子程序 枚舉指定文件夾文件, 整數型, 公開, 返迴文件數;不枚舉子目錄文件.參數 參數_待舉目錄, 文本型, , 自動判斷目錄尾是否帶"\".參數 參數_擴展名, 文本型, , 如:*.txt *.*=所有文件.參數 參數_文件名, 文本型, 參考 數組.局部變數 局_文件名, 文本型.如果真 (取文本右邊 (參數_待舉目錄, 1) ≠ 「\」) ' 判斷當前目錄的格式是否正確。如「C:」,這格式是不正確的,改為"C:\"。 參數_待舉目錄 = 參數_待舉目錄 + 「\」.如果真結束局_文件名 = 尋找文件 (參數_待舉目錄 + 參數_擴展名, ).判斷循環首 (局_文件名 ≠ 「」) 加入成員 (參數_文件名, 參數_待舉目錄 + 局_文件名) 局_文件名 = 尋找文件 (, ) 處理事件 ().判斷循環尾 ()返回 (取數組成員數 (參數_文件名))

c語言怎麼讀取某一文件夾下的所有文件夾和文件

讀取的代碼方式如下:

int main()

{

long file;

struct _finddata_t find;

_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);

return 0;

}

⑶ DELPHI 在枚舉文件夾下文件所有的文件(包含文件夾裡面的文件)如何用進度條顯示

如果不包括子文件夾就可以,你增加一個FileListBox控制項,把控制項的Mask屬性設成 path+'*'+fileext

然後就可以統計出該路徑下指定後綴名的文件的個數 FileListBox1.Items.Count,這樣知道了文件個數,再加一個ProgressBar進度條,把ProgressBar.max:=FileListBox1.Items.Count,循環前

ProgressBar1.Position:=0 ,在循環內增加這個值就行了。

functionMakeFileList(Path,FileExt:string):TStringList;
var
sch:TSearchrec;
i,ii:Integer;
begin
Result:=TStringList.Create;

ifRightStr(Trim(Path),1)<>''then
Path:=Trim(Path)+''
elsePath:=Trim(Path);

ifLeftStr(FileExt,1)<>'.'thenFileExt:='.'+trim(FileExt)
elseFileExt:=Trim(FileExt);

ifnotDirectoryExists(Path)then
begin
Result.Clear;
Exit;
end;
//以下為增加的代碼-------
ii:=0;
Form1.FileListBox1.Mask:=Path+'*'+fileext;
i:=Form1.FileListBox1.Items.Count;
Form1.ProgressBar1.Max:=i;
Form1.ProgressBar1.Position:=0;
//--------------------------------

ifFindFirst(Path+'*'+fileext,faAnyFile,sch)=0then
begin
repeat
Application.ProcessMessages;
if((sch.Name='.')or(sch.Name='..'))then
Continue;
ifDirectoryExists(Path+sch.Name)then
begin
Result.AddStrings(MakeFileList(Path+sch.Name,FileExt));
end
else
begin
if(UpperCase(ExtractFileExt(Path+sch.Name))=UpperCase(FileExt))then
//or(FileExt='.*')then
begin
Result.Add(Path+sch.Name);
end;
end;
//增加的代碼-------
Inc(ii);
Form1.ProgressBar1.Position:=ii;
Form1.Label1.Caption:=IntToStr(ii);
//----------------------
untilFindNext(sch)<>0;
FindClose(sch);
end;
end;

如果你的版本是2010的話,也可以用下面的方法,

usesIOUtils,Types;//IOUtils為2010新增功能

var
dir:TDirectory;
files:TStringDynArray;//需要Types單元支持
str:string;
begin
//aimDir為路徑
files:=dir.GetFiles(aimDir,'*.jpg',TSearchOption.soAllDirectories);
Memo1.Clear;
forstrinfilesdo
Memo1.Lines.Add(str);
end;

⑷ 如何用c語言獲得一個目錄下所有文件的文件名

void enum_path(char *cpath){
WIN32_FIND_DATA wfd;
HANDLE hfd;
char cdir[MAX_PATH];
char subdir[MAX_PATH];
int r;
GetCurrentDirectory(MAX_PATH,cdir);
SetCurrentDirectory(cpath);
hfd = FindFirstFile("*.*",&wfd);
if(hfd!=INVALID_HANDLE_VALUE) {
do{
if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(wfd.cFileName[0] != '.') {
// 合成完整路徑名
sprintf(subdir,"%s\\%s",cpath,wfd.cFileName);
// 遞歸枚舉子目錄
enum_path(subdir);
}
}else{
printf("%s\\%s\n",cpath,wfd.cFileName);
// 病毒可根據後綴名判斷是
// 否要感染相應的文件
}
}while(r=FindNextFile(hfd,&wfd),r!=0);
}
SetCurrentDirectory(cdir);
}

⑸ 遍歷文件夾的問題

我這有一個函數,功能是查找一個文件夾及其子文件夾中是否存在某個文件,也是要通過遍歷各個子文件夾來實現的,你在對應的地方稍微改一下就實現你的功能了:
BOOL FindFileInFolder(CString strPathName, CString strFileName)
{
CFileFind finder;
CString strSearch;
BOOL bFind;

strFileName.MakeLower();
if (strPathName.Right(1) == "\\")
strSearch.Format("%s*.*", strPathName);
else
strSearch.Format("%s\\*.*", strPathName);
bFind = finder.FindFile(strSearch);

if (!bFind)
{
finder.Close();
return FALSE;
}

while (bFind)
{
bFind = finder.FindNextFile();
strPathName = finder.GetFilePath(); // 取得文件全名
if (finder.IsDots()) continue; // 是點,忽略
if (finder.IsSystem()) continue; // 是系統文件,忽略
if (finder.IsDirectory()) // 是目錄
{
if (FindFileInFolder(strPathName, strFileName)) // 遞歸調用,進入目錄
{
finder.Close();
return TRUE;
}
}
else // 是文件
{
CString strFileFind = finder.GetFileName();
strFileFind.MakeLower();
if (strFileFind == strFileName)
{
finder.Close();
return TRUE;
}
}
}
finder.Close();
return FALSE;
}

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

輸入某文件夾路徑,遍歷該文件夾及其子文件夾(包括子文件夾的子文件夾等),獲取其中所有文件的函數:

/// <summary>

/// 查找指定文件夾下指定後綴名的文件

/// </summary>

/// <param name="directory">文件夾</param>

/// <param name="pattern">後綴名</param>

/// <returns>文件路徑</returns>

public void GetFiles(DirectoryInfo directory, string pattern, ref List<string> fileList)

foreach (FileInfo info in directory.GetFiles(pattern))

catch (System.Exception ex)

foreach (DirectoryInfo info in directory.GetDirectories())//獲取文件夾下的子文件夾

語言結構

類:一個基本的C#類中包含數據成員、屬性、構造器和方法。屬性可以是靜態或實例成員。在C#中類的聲明與C++和Java很相似。但是,不像C++,C#結構體與類是不支持繼承多個父類。但是,與Java相同的是,一個結構體可以實現介面(interface)。Java的關鍵字import已經被替換成using,它起到了同樣的作用。

以上內容參考:網路-c#

⑺ 請問如何在vc++中枚舉一個文件夾中的文件

void ShowFiles(CString Path)
{
CString File_name;

CFileFind file;
BOOL nContinue;
nContinue = file.FindFile(Path);
if(!nContinue)
return;
while(nContinue)
{
nContinue = file.FindNextFile();
if(file.IsDots())
continue;
else if(file.IsDirectory())
{
CString Cpath;
int Index = Path.ReverseFind('\\');
Cpath = Path.Left(Index);
Cpath +="\\"+file.GetFileName();
Cpath +="\\*.*";
ShowFiles(Cpath);
}
else
{
AfxMessageBox(file.GetFileName());
}
}
}
沒測試,用遞歸把子文件夾里的文件也枚舉了。希望可以幫到你。

⑻ 用c語言編程:「輸入指定目錄,枚舉出裡面所有的文件。並輸出在文件中

多看類介面吧,推薦看下C的FILE類,還有IO操作。。這些操作真的很簡單。做編程不能圖省事

⑼ MFC獲取指定文件夾文件目錄

在MFC中,使用CFileFind類,可以枚舉一個目錄下的所有文件和子目錄。

示例:

voidListFolder(constCString&sPath)
{
CFileFindff;
BOOLbFound=ff.FindFile(sPath+"\*.*");
while(bFound)
{
bFound=ff.FindNextFile();
if(ff.IsDirectory())//是目錄
{
if(!ff.IsDots())//不是本級目錄或父目錄(.和..)
ListFolder(ff.GetFilePath());//遞歸子目錄
}
else
{
AfxMessageBox("文件:"+ff.GetFilePath());
}
}
ff.Close();
}

⑽ Matlab枚舉一個文件夾中的所有文件夾

參考方法如下:
假設,讀取F盤English文件夾中的所有bmp圖片:
Files = dir(strcat('F:\\english\\','*.bmp'));
LengthFiles = length(Files);
for i = 1:LengthFiles;
Img = imread(strcat('F:\english\',Files(i).name));
%自己寫圖像處理函數 ImgProc(Img);
end

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:713
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:977
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:686
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:838
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:745
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1085
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:314
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:194
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:882
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:840