List of files and directories in C++ ??
How do I get a list of all the Directories and Files in a Directory (like c:\MyFiles\) ?
I need to do this beacuse I´m making a Resource File Builder.
Hope anybody can help !
-- There IS something rotten in the state of Denmark --
-------------Ban KalvinB !
What are you using Win32 or DOS?
if it is Win32, you can use the opendialogs to get file names etc. to get directories (like in the add new hardware dialog) you have to use an undocumented Win32 function, i''ve forgotten it, but it definitely there (if you need it email me)
other wise you have to use the FindFirstFile (or something similar) and FindNextfile. I think.
PS. I haven''t done much file manipulation for a while ...
Hope this isn''t to vague to be of much use, I rely on my compiler (BCB)''s many file functions, also because when BCB is ported to linux I don''t have to change anything, to port! just recompile. (wait... off topic... oops).
if it is Win32, you can use the opendialogs to get file names etc. to get directories (like in the add new hardware dialog) you have to use an undocumented Win32 function, i''ve forgotten it, but it definitely there (if you need it email me)
other wise you have to use the FindFirstFile (or something similar) and FindNextfile. I think.
PS. I haven''t done much file manipulation for a while ...
Hope this isn''t to vague to be of much use, I rely on my compiler (BCB)''s many file functions, also because when BCB is ported to linux I don''t have to change anything, to port! just recompile. (wait... off topic... oops).
I´m using win32..
Does anybody know the above mentioned undocumented functions ?
I want the user to specify one directory (no problem) and make the program add all files in all sub-dorectories to the resource file.
Therefore I need to know all subdirectories and all files in all the sub directories....
I have a feeling nobody can answer this...Typical.......
-------------Ban KalvinB !
c++freak is right
It''s a time away since I did this, but I think it was
FindFirst
and
FindNext
Both functions'' description should be available in your MSDN. If not you should search the internet
It''s a time away since I did this, but I think it was
FindFirst
and
FindNext
Both functions'' description should be available in your MSDN. If not you should search the internet
Then there is the somewhat-easy somewhat-evil way. If you are using MSVC++ you can use the System() function (or maybe system()). It works like this:
PS - I think something is wrong with my [ source ] tags...
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
char Buffer[80];sprintf(Buffer, "%s*.* > filelist.txt", Path); // the path of your choice aka "c:\myfiles\"system(Buffer);FILE *file = fopen("filelist.txt", "r");char FileName[8];char FileExt[3];while (fscanf(file, "%s.%s\t%s", FileName, FileExt, Buffer) != EOF){ // add file name and extention to whatever your doing}[/source]I think that will work... you may need to play around with the exact format of the text file. If you need the file name, extention and path like you probably will, try the following inside the loop:[source]sprintf(Buffer, "%s%s.%s", Path, FileName, FileExt);
PS - I think something is wrong with my [ source ] tags...
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
Visit the ROAD Programming Website for more programming help.
Edited by - Yanroy on September 11, 2000 11:41:53 AM
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
it''s not undocumented, i think c++freak was talking about SHBrowseForFolder. that function displays a folder selection box, like driver selection. use FindFile fxns like so:
crazy166
some people think i'm crazy, some people know i am
WIN32_FIND_DATA fd; HANDLE findHandle = FindFirstFile( "C:\\folder\*.*", &fd ); if ( findHandle != INVALID_HANDLE_VALUE ) { do { //here, fd.dwFileAttributes and fd.cFileName //should contain whatever information you need } while ( FindNextFile( findHandle, &fd ) ); FindClose( findHandle ); }
crazy166
some people think i'm crazy, some people know i am
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement