Windows中该文件夹及其子文件夹内的所有文件的列表 [英] List of all files inside the folder and its subfolders in Windows
问题描述
我想通过访问"C:\ windows \ system32 \ Tasks" 目录中的所有文件来列出在Task Scheduler下运行的所有文件.
I want to list all the files that run under Task Scheduler by accessing all the files in the "C:\windows\system32\Tasks" Directory.
该程序应递归地保持打开目录中的子文件夹并列出所有文件.我目前使用 Windows操作系统.
The program should recursively keep opening subfolders in the directory and list all the files. I currently use Windows OS.
我尝试使用COM库,但是它没有在子文件夹中显示任务.我有60个任务,但仅显示12个.因此,我尝试遍历Tasks文件夹.
I tried using the COM library but it doesn't display the tasks in the subfolders. I have 60 tasks but it displays only 12. So, I'm trying to iterate through the Tasks folder instead.
#include <stdio.h>
#include <dirent.h>
int main(void)
{
DIR *dir;
struct dirent *de;
if ((dir = opendir("C:\\Windows\\System32\\Tasks")) != NULL);
{
printf("The startup Programs are:\n");
while ((de = readdir(dir)) != NULL)
{
printf("%s\n", de->d_name);
}
closedir(dir);
}
getchar();
}
我希望输出显示当前文件夹及其子文件夹中的所有文件. 但是,输出仅显示第一个文件夹的名称并退出.
I expected the output to display all the files inside the current folder and the subfolders. However, the output only displays the name of the first folder and exits.
推荐答案
由于显然没有在Windows下递归列出目录的完整,简单的示例,因此这里是一个:
As there is apparently no full, simple, example of recursively listing directories under windows, here is one:
#include <windows.h>
#include <stdio.h>
void listdirs(char *dir, char *mask)
{
char fspec[1024], fname[1024];
WIN32_FIND_DATA dta;
HANDLE hDta;
sprintf(fspec,"%s/%s",dir, mask);
if ((hDta= FindFirstFile (fspec, &dta)) != INVALID_HANDLE_VALUE) {
do {
if ( !(dta.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
{
printf ("%s/%s\n", dir, dta.cFileName);
}
else
{
if (strcmp(dta.cFileName,".")!=0 && strcmp(dta.cFileName,"..")!=0 )
{
sprintf (fname, "%s\\%s", dir, dta.cFileName);
listdirs(fname, mask);
}
}
} while (FindNextFile (hDta, &dta));
FindClose(hDta);
}
}
int main (int argc, char *argv[])
{
listdirs(argv[1],argv[2]); // Usage: progname c:\MyDir *.*
return 0;
}
这篇关于Windows中该文件夹及其子文件夹内的所有文件的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!