Sign in to follow this  

Problem with WINAPI converting from TCHAR to string

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

[code]
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);
}



}[/code]


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 [/size][/font][/color]

Share this post


Link to post
Share on other sites
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

This topic is 2341 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this