linux下c++获取指定目录及其子目录下所有文件(国外英文资料).doc
文本预览下载声明
linux下c++获取指定目录及其子目录下所有文件(国外英文资料)
/ / create time: 2013-05-13 11:34:00
/ / the author: LPH
/ * this CPP file function is:
* get all files of the directory you input in CMD line!
* if you want to test this CPP file you must in Linux systems!
* /
/ / it may be possible to compile the Linux system for use. Windows is missing
/ / some environment in the Linux system, and the header file.
/ / the directory you are looking for must have permissions for the current user, otherwise the statistics cannot be opened
# include iostream
# include dirent. H
# include sys/stat.h
# include vector
# include string. H
# include algorithm
# include stdlib. H
# define MAX_COUNT 100 / / if you find a lot of files, more than 100, 100 per click
# define FILE 0 / / find the FILE
# define DIRECTORY 1 / / find the DIRECTORY
Using namespace STD.
/ / return directory dir, filetype file or directory, return one at a time, not return ,
String getContent (const char * dir, string filetype = , int fileOrDir = FILE);
/ / get a list of the filetype files under directory dir and the directory under dir
Vector string getall (const char * dir, string filetype = , int fileOrDir = FILE);
/ / the function to sort the return list is to compare two string sizes
Bool fileCmp (string file1, string file2);
/ / convert lowercase characters in a string string to uppercase
String STR;
/ / directory number
Int dirCount = 0;
/ / file number
Int fileCount = 0;
Int main (int argc, char * argv [])
{
/ / at least two parameters, command + directory, can also be added to a file type
If (arg c 2)
{
Cout endl
//// //
/ a.u/home/localhost/SRC /.cpp
. / a.ut/home/localhost/SRC/CPP.
The return - 1;
}
String stropt = ;
/ / determine if the directory exists. If not, if the prompt is created, enter y, create, otherwise nothing!
If (argv [1], F_OK)! = 0)
{
Cout
String STR = ;
Cin STR.
If (STR. At (0)
显示全部