文件管理 · 2022年9月29日

c搜索指定文件夹|C语言怎么读取某一文件夹下的所有文件夹和文件

① c++中如何搜索一个目录下面所有文件夹名,

据我了解C++中没有这样的函数,但是你可以自己写一个这样的函数1. 首先判断你的参数是一个文件还是一个路径2. 如果是一个文件,直接递归的查找,并且返回路径3. 如果是目录,首先递归的查找文件夹,找到文件夹之后判断文件夹中是否有这样的文件,如果有返回找到的路径,没有就返回false

② C# 如何查找指定文件夹 并获得它的路径

你需要找到这个文件夹的盘符,或者指定到它的父级,再使用System.IO.Directory.GetDirectories(path)获取它的子文件夹信息.

③ C里面怎么实现指定一个文件夹目录 查询文件夹内是否有这个文件,假如有就复制这个文件到我指定的目录下。

可以使用findfirst函数查找,用system()函数复制。

④ 怎么用c语言(或者用别的)输入一个文件名(带后缀)自动在某个盘里面搜索其路径

#include<stdio.h>#include<stdlib.h>int main(){ //将f改成你要搜索的文件的文件名 char f[]="233.exe";char p[128]={'\0'};FILE *inf=NULL;int i;for(i=65;i<91;i++){p[0]=(char)i;strcpy(p+1,":\\");strcpy(p+3,f);inf=fopen(p,"r");if(inf){printf("%s\n",p);fclose(inf);}}system("PAUSE"); return EXIT_SUCCESS; }

⑤ C语言:如何遍历指定的文件夹(可以包括子文件夹)中的每一个文件名

Function SearchFiles(Path As String, FileType As String)Dim Files() As String '文件路径Dim Folder() As String '文件夹路径Dim a, b, c As LongDim sPath As StringsPath = Dir(Path & FileType) '查找第一个文件Do While Len(sPath) '循环到没有文件为止 a = a + 1 ReDim Preserve Files(1 To a) Files(a) = Path & sPath '将文件目录和文件名组合,并存放到数组中 List1.AddItem Files(a) '加入控件中 sPath = Dir '查找下一个文件 DoEvents '让出控制权LoopsPath = Dir(Path & "\", vbDirectory) '查找第一个文件夹Do While Len(sPath) '循环到没有文件夹为止 If Left(sPath, 1) <> "." Then '为了防止重复查找 If GetAttr(Path & "\" & sPath) And vbDirectory Then '如果是文件夹则。。。。。。 b = b + 1 ReDim Preserve Folder(1 To b) Folder(b) = Path & sPath & "\" '将目录和文件夹名称组合形成新的目录,并存放到数组中 End If End If sPath = Dir '查找下一个文件夹 DoEvents '让出控制权LoopFor c = 1 To b '使用递归方法,遍历所有目录 SearchFiles Folder(c), FileTypeNextEnd FunctionPrivate Sub Command1_Click() '调用SearchFiles "e:\", "*.exe"End Sub

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

}

⑦ 在c语言中读写文件如何查找特定名称的文件

打开文件,遍历文件内容然后一个一个匹配查找就好了。

⑧ C语言怎么列出指定文件夹或者分区里面的文件和文件夹

//以下是c++方法#include<stdio.h>#include<io.h>#include<string.h>#include<string>#include<iostream>usingnamespacestd;#defineWIDTH300#defineH40intlen=0;stringfiles[1000];voidgetFiles(stringpath,intdeepth){longhFile=0;struct_finddata_tfileinfo;stringp;if((hFile=_findfirst(p.assign(path).append("\*").c_str(),&fileinfo))!=-1){do{if(fileinfo.attrib&_A_SUBDIR){//想取子文件夹里的内容,这里可以用以下代码,deepth控制深度//getFiles(path+"/"+fileinfo.name,deepth+1);}else{files[len]=fileinfo.name;++len;}}while(_findnext(hFile,&fileinfo)==0);_findclose(hFile);}}stringpath="E:/";voidmain(){inti,res;getFiles(path,0);for(i=0;i<len;++i)puts(files[i].c_str());Sleep(800);return;}

⑨ 问一个关于C#的题,怎么从一个指定的文件夹中搜索指定文件名的文件最好能用到FileInfo和DirectoryInfo。

搜出 F:\我们的歌 文件夹里面 所有的"播放列表"+数字.txt的所有文件么 用正则表达式吧 ~ ArrayList playListArray = new ArrayList(); String direcName = @"F:\我们的歌"; // String fileName = "播放列表" + numberOfPlaylistFiles + ".txt"; DirectoryInfo di = new DirectoryInfo(direcName); foreach (FileInfo file in di.GetFiles("*.txt")) { System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex("播放列表(\\d+).txt"); if (rgx.IsMatch(file.Name)) playListArray.Add(file.Name); } // numberOfPlaylistFiles++; // numberOfLoops–;for (int i = 0; i < playListArray.Count; i++) { Console.WriteLine(playListArray[i].ToString()); }

⑩ 如何根据指定目录从一个文件夹中(含子文件夹)中搜索对应文件并自动复制至新路径下

不清楚你的实际文件/情况,仅以问题中的样例说明及猜测为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI

@echooff&cd/d"%~dp0"&modeconlines=5000rem根据给出的对应关系,从一个目录里查找出指定名称的文件,并拷贝/复制到另一个目录的指定子文件夹里set#=Anyquestion&set_=WX&set$=Q&set/az=0x53b7e0b4title%#%+%$%%$%/%_%%z%set"oldfolder=D:大文件夹"set"newfolder=I:材料"ifnotexist"%oldfolder%"(echo;"%oldfolder%"未找到&pause&exit)for/f"delims=:"%%ain('type"%~f0"^|findstr/in"^exit$"')doset"last=%%a"for/f"skip=%last%tokens=1*delims=="%%ain('type"%~f0"')do(for/f"delims="%%cin('dir/a-d-h/b/s"%oldfolder%\%%~b.*"2^>nul')do(echo;"%%~c"–^>"%oldfolder%\%%~a"))echo;%#%+%$%%$%/%_%%z%pauseexit0001=转征函【2016】1093号0002=转征函[2017]1446号0003=转征函[2015]1122号0004=转征函[2017]1446号0005=转征函[2017]1446号0006=转征函[2012]8460007=转征函[2015]1122号