Jump to content
  • Advertisement
Sign in to follow this  
JacekChronowski

Problem with WINAPI converting from TCHAR to string

This topic is 2560 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


void Find(char *curdir)
{

WIN32_FIND_DATA wfd; //zmienna zawieraj?ca informacje o pliku
bool IsFile=true; // flaga mówi?ca o tym czy mamy kolejny plik w danym katalogu
HANDLE hFile; //zmienna do przeskakiwania do kolejnego pliku w bie??cym katalogu
char path[200]; //scie?ka dost?pu do danego pliku
//int length=strlen(roz);

SetCurrentDirectory(curdir);

hFile=FindFirstFile("*.*",&wfd);

cout << path << endl;

system("pause");
while(IsFile)
{

GetFullPathName(wfd.cFileName,199,path,NULL);

if((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (wfd.cFileName[0] != '.'))
Find(path);

//if(Porownaj(&wfd,length))//krotka funkcja porównuj?ca rozszerzenie
//Kopiuj();


IsFile=FindNextFile(hFile,&wfd);
}



}



i'm begginer i don't know Winapi very well . I have variable wfd - how from attribute [color=#333333][font=Verdana, Arial, Helvetica, sans-serif][size=2]cAlternateFileName get file's extension and having it in string [/font]

Share this post


Link to post
Share on other sites
Advertisement
You can find the extension by searching the string for the last occurrence of the '.' character.

If I were writing your program I'd be suspicious of setting the current directory in a recursive function. Changing the current directory mid program can make the programs behaviour change (relative files that once loaded correctly may now fail, relative files you open could end up anywhere on the hard drive).

A simple fix is to revert the current directory when returning from the function (be sure to handle unusual cases such as exceptions). Another fix is to split this function in two, one that works with absolute paths and another one that works with relative paths, this latter one can use GetCurrentDirectory(), append the relative path and then calls the absolute function.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!