Jump to content
  • Advertisement
Sign in to follow this  
Samurai Jack

"C" List files of directory with path?

This topic is 4162 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greetings! I am writing a windows specific c++ application without MFC. It is a converter, but there is a catch - let me explain it with an example: convert.exe c:/samples/pictures/*.bmp [enter] when I use something like that:
struct _finddata_t fileInfo;
intptr_t hFile = _findfirst("c:/samples/pictures/*.bmp", &fileInfo);
if (hFile != -1L)
{
do
{
printf("File: %s\n", fileInfo.name);
}while (_findnext(hFile, &fileInfo) == 0);
_findclose(hFile);
}
I am not able to extract any "PATH" name out of _finddata_t (fileInfo). Does anyone have a suggestion? I would like that if you say: convert c:/samples/pictures/*.bmp you get c:/samples/pictures/*.dat for example and not currentfolder./file.dat! I do not want to use string parsers neither!

Share this post


Link to post
Share on other sites
Advertisement
Copy fileInfo.name into a buffer, then start with the last character in the buffer and search backwards through it checking if each character matches a forward slash. Replace the first matching forward slash with '\0' and now the buffer contains the path without the filename.

Alternatively, investigate the strrchr function.


See also:
Double-Byte Safety Primer
The Complete Guide to C++ Strings, Part I - Win32 Character Encodings

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!