| | |
Listing files in a folder
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I am trying to access files in a folder. The folder name and location will be given - the program will search inside the files in that folder for a specific pattern(yup like grep). However, I am not sure how to actually let my program know what are the files available and access them one by one.
I could use pipe in unix or linux. As for Win XP I could only think of using the system("dir > tmpfilename") and thus saving the output it into a temporary file. Then taking the file names from that file.
Please let me know if anyone of you have a better idea as how to do the job. I cannot use win32 because the program would be used as an example in a class introducing the C programming language. So it means no C++ as well. Is there any way to make the code portable(I doubt)?
I could use pipe in unix or linux. As for Win XP I could only think of using the system("dir > tmpfilename") and thus saving the output it into a temporary file. Then taking the file names from that file.
Please let me know if anyone of you have a better idea as how to do the job. I cannot use win32 because the program would be used as an example in a class introducing the C programming language. So it means no C++ as well. Is there any way to make the code portable(I doubt)?
"He who mixes with people and endures the harm they do is better than he who does not mix and endures." (Tirmidhi)
On MS-Windows, use FindFirstFile() and FindNextFile(). There are lots of examples how to use those two functions floating around, just use google to search for them.
>>I cannot use win32 because the program would be used as an example in a class introducing the C programming language
How to get those filenames is an os-specific task -- you will have to use win32 api functions. Yes, they can be used in console applications, just include windows.h. And it does not require any knowlege of c++. But it does require a little more then absolute beginner's knowledge. Need to know about loops, and structures and character arrays. If that is too much then you probably should pick a different example.
>>I cannot use win32 because the program would be used as an example in a class introducing the C programming language
How to get those filenames is an os-specific task -- you will have to use win32 api functions. Yes, they can be used in console applications, just include windows.h. And it does not require any knowlege of c++. But it does require a little more then absolute beginner's knowledge. Need to know about loops, and structures and character arrays. If that is too much then you probably should pick a different example.
![]() |
Similar Threads
- scanning files in a spec folder (JavaScript / DHTML / AJAX)
- how to copy all files from one folder to another using system.io (ASP.NET)
- please help search files in folder (C++)
- Access to "Temporary Internet Files" folder (Windows 95 / 98 / Me)
- listing all files on hard drive? (Windows NT / 2000 / XP)
- Cant upload dreamweaver "files folder" to site (Networking Hardware Configuration)
- Courrpt Files (Windows 95 / 98 / Me)
- Temporary Internet Files Folder (Web Browsers)
Other Threads in the C++ Forum
- Previous Thread: Help, i suppose
- Next Thread: get werid error when splitting up my code
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






