Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* FILESYSTEM OPERATIONS EXAMPLE
- *
- * This program gets the list of files in the directory from which this program
- * is ran, and outputs said list without sorting it.
- *
- * This program uses <dirent.h> to accomplish this. However, there's no
- * standardized library to do this in C++.
- *
- * I apologize in advance for making this program run in its entirety within
- * main().
- */
- #include <dirent.h>
- #include <iostream>
- using namespace std;
- int main(){
- // initialize variables
- DIR *dp; // pointer used to store files list
- struct dirent *dirp; // pointer to an item in files list
- string db[64]; // database to which the files list will be written to
- char index = 0;
- // open the directory and fill db[] with its contents
- dp = opendir("./");
- while((dirp = readdir(dp)) != NULL){
- db[index] = string(dirp->d_name);
- index ++;
- }
- closedir(dp);
- // output db[]
- for(char i = 0; i < index; i ++){
- cout << db[i] << endl;
- }
- // the end
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement