i am trying to write a program that finds files in a folder recursively but i am not sure how to pass ofstream reference when i am running my program it runs successfully but when i open the file its empty ca someone please tell me where i am wrong.
Are you sure there are any regular files in the root of drive "F:"? Your program only appears to list the directories in the directory provided, it doesn't navigate to any other sub directories.
i solved above problem i was passing just file address with stat, i replaced it with absolute address by adding addr to ent->d_name and it worked but now i am having another problem files present in the first child folder are not written in output file rest all files of other folder are being written i don't know what is happening
Change the name associated with the ofstream object to a non-existing file instead of files.txt and see if that works. Also try and put in state flag checks throughout browse() and see if it generates any messages
I opened ofstream inside browse function and it worked but it is not a good practice i guess, now ofstream is opened and closed every time browse function is called
I have never passed ofstream as reference before, can anybody help me change this code to pass ofstream reference from main, so that ofstream is opened and closed only once during program run.
I have never passed ofstream as reference before, can anybody help me change this code to pass ofstream reference from main, so that ofstream is opened and closed only once during program run.
The very first post in this thread is an example, at least with regard to the ofstream.
yes but that very first program is giving weird output, it is not including all files in the directory. I ran that code for a directory having lots of folder and sub folders in it, although the cout listed all files but when i opened output file it had only one file name in it then i thought there must be some problem with the ofstream reference so i moved ofstream inside browse function and it started listing all files in the output file too.
A slight variation. Essentially the same code as before, but with two changes.
1. defer the processing of subdirectory until after ordinary files
2. allow capture of console output to another file.