1. Add header file Dirent.h
Declares the structure body pointer struct dirent * PTR;
Declares a dir pointer dir * FD;
2. Analysis command line
3. Open catalog File
Using the Opendir () parameter to parse the second parameter of the command line Argv, return the directory file pointer value to the FD
4. Output redirection
Use the Freopen () parameter to parse the third parameter of the command line argv, permission "w+", File descriptor Stdtout
5. Start reading catalog file contents
Using the Loop while (Ptr=readdir (FD)!=null), Readdir () extracts a file item from the catalog file each time, and the pointer moves forward. Until the end of the file returns a null value. The PTR pointer points to the DIRENT structure returned by Readdir (), each time the function call returns a different dirent of the member contents, where the value of the D_name member is the name of the file in the directory that is read each time. Using the original mstat.c in the JoJo to obtain the file information code will ptr->d_name to do fopen (), Fstat () parameters, you can print out the directory of all the files in the information and into the output file.
6. Close all file and directory file pointers .