List of all .txt file [closed]
Hi I want to write a program that give a path in my system and goes to that path and search in that path and sub-directory of path and list all of .txt file . please help me . thanks .
The Following code will list all your files in "C:\Windows\System32" directory (SYSDIR for XP system). Add it in your code however you want.
DIR *dir;
struct dirent *ent;
dir = opendir ("c:\\Windows\\System32");
if (dir != NULL) {
/* print all the files and directories */
while ((ent = readdir (dir)) != NULL) {
printf ("%s\n", ent->d_name);
}
closedir (dir);
} else {
/* Can not open directory */
perror ("");
return EXIT_FAILURE;
}
Create an object of type QDir
. This can be used to navigate to the desired folder, e.g. by using dirobj.cd("/mypath/somewhere")
. Then use dirobj.entryList(QStringList("*.txt", "*.otherext", ...)
to retrieve a list of the files found.
精彩评论