This little C++ Program will create a file "list.txt" containing an inventory of all files in a given directory. It is useful for generating lists of media files such a music and video's to keep track of what you have and don't have without a media player.
/* * Program to print out the contents of a given directory * This program is to be run from the directory of which * the user wishes to list contents * * Intended use is for listing all media files in a collection * Allowing for cataloguing and management of content. * * Enjoy . */ #include <dirent.h> #include <stdio.h> #include <fstream> using namespace std; void list_and_print() { DIR *myDirectory; struct dirent *dir; ofstream myOut("list.txt"); //file created with contens listed in dir. myDirectory = opendir("."); // Will list the current directory. /// myDirectory = opendir("windows/C/Documents and Settings/All Users/Documents/My Music/"); if (myDirectory) { while ((dir = readdir(myDirectory)) != NULL) { //print our directory information printf("%s\n", dir->d_name); myOut << dir->d_name << endl; } closedir(myDirectory); printf("A file list.txt has been created in current directory,\nThis file contains the file listing.\n"); } } //want to open dir int main() { printf("This Simple Program Prints and creates a file list.txt,\ncontaining all filenames in a given directory\nEnjoy\n\n+++++++Files+++++++\n\n"); list_and_print(); return 0; }
