943,962 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 268
  • C++ RSS
Nov 11th, 2009
0

Please Help : Urgent

Expand Post »
help me in listing file names inside directory by using a simple code in c++ that a beginner can understand
Similar Threads
Reputation Points: 3
Solved Threads: 0
Newbie Poster
Ashishinani1756 is offline Offline
10 posts
since Sep 2009
Nov 11th, 2009
0
Re: Please Help : Urgent
Last edited by dkalita; Nov 11th, 2009 at 7:57 am.
Reputation Points: 121
Solved Threads: 61
Posting Pro in Training
dkalita is offline Offline
402 posts
since Sep 2009
Nov 11th, 2009
0

windows files enumeration

help me in listing file names inside directory by using a simple code in c++ that a beginner can understand
i believe that enumerating files/directories is OS dependent. so assuming your on windows, here are a few code snippets that will help you find files in a directory. the functions are defined in <windows.h>

WIN32_FIND_DATA fileData;
HANDLE hFind = FindFirstFile("C:\WINDOWS\*.exe", &fileData);

this will get the first .exe file that it can find in C:\WINDOWS, and fill the file's information into fileData

FindNextFile(hFind, &fileData)

calling this function will then get the next file matching that pattern. FindNextFile(...) will return NULL when it cant find anymore files.

note that subdirectories are sorta considered files, so will also be returned if they match the pattern (eg you use "C:\WINDOWS\*"), so you can check what is a directory (ie not a file) with:

fileData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY

so, using these functions in a simple do-while loop will cycle through every file or subdirectory in a particular folder
Reputation Points: 10
Solved Threads: 0
Newbie Poster
skp888 is offline Offline
3 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: factorial problem
Next Thread in C++ Forum Timeline: i want function to know the active language in windows





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC