Author: Qing Dujun
We know that DIR is the display directory. But how do I save the file name in the directory?
Several knowledge points are required:
I,DIR: Displays the file name (including summary) in the directory)
II,DIR/B: Only show the file name
III,DIR/B> 1.txt: Import the contents to the 1.txt file for storage.
IV,Del d: \ 1.txt: Delete D: The 1.txt file under the drive (if you want to delete the folder, use rm D: folder name)
V,DEL/q d: \ 1.txt: Force Delete, no need to confirm
VI,Fgets (): Reads a row from a file at a time.
Example: output the name of the bottom file in the XXX directory
Program ideology:
First, store the directory in the file, and then read the file until the last one.
# Include
# Include
Int main () {FILE * fp = NULL; char save [100]; system ("dir/B E: \ Ock \ DirSave> D: \ buf. ock "); // export the directory to buf. ockfp = fopen ("D: \ buf. ock "," rb "); while (! Feof (fp) {fgets (save, 100, fp);} fclose (fp); system ("del/q d: \ buf. ock "); // delete D: buf under the directory. ock file puts (save); // display the last file name return 0 ;}
Of course, you can obtain the path required by DIR from the parameters of the main () function:
#include
int main(int argc, char **argv){puts(argv[0]);return 0;}
Argv [0] content. This is the current directory. You can extract the desired path by yourself ~~~~
Use DIR/B D: to display the file directory diagram.