Skip to main content
GameDev.net gamedev.net
🔒 Locked

FindFirstFile w/ Path ???

Started by Tonic151 Jun 13, 2002 at 3:36 PM 2 replies 800+ views
Original Post
Tonic151
Tonic151
I'm having a really hard time trying to get a Path to work with FindFirstFile.. Heres my fuction at present..
      

	WIN32_FIND_DATA wfd;
        HANDLE          h;
        LOGNAME         log;
        
        h = FindFirstFile("l*.log", &wfd);
        if(h != INVALID_HANDLE_VALUE) {

	// Do Junk Here..  


        }
        while(FindNextFile(h, &wfd)) {
		
		// Do More junk Here


                }
        }
        FindClose(h);

    
What i'm trying to do is.. I have a std::string LOGPATH; This holds the path to where i want to find the files.. but i can't figure out how to get it to work in place of this... h = FindFirstFile("l*.log", &wfd); the "l*.log" is the while card i want to find in the directory.. but how do i insert the path in.. I keep getting need char.. And so i tried this...
       

	string tpath = LOGPATH;
        tpath += tpath+"l*.log";     
        
        TCHAR file[256];
        and char file[256];  // Both of these do the same...


        strcpy(file,tpath.c_str());

        h = FindFirstFile(file, &wfd);
      
It compiles ok and everything, but when i run it i get a memory exception error in windows.. Anyone know whats wrong? [edited by - tonic151 on June 13, 2002 4:40:36 PM]
_johan
_johan
Use SetCurrentDirectory
Tonic151
Tonic151
quote:
Original post by _johan
Use SetCurrentDirectory




Ahhh Doh.. Thanks!!!!
IndirectX
IndirectX
SetCurrentDirectory will work, but the current directory is global for the entire process so modifying it should be viewed as the last resort, and if you do modify it, be sure to restore the old value, otherwise you might not be able to find data files that are stored relative to the "current directory" since you changed to to point somewhere else.

>> tpath += tpath+"l*.log";
You''re appending tpath to itself, which probably isn''t what you want.

The simple way is to use SHELLAPI Path functions, such as PathAppend. It will take care of backslashes and so on. If you don''t want to use SHELLAPI [*], you can write your own equivalent to PathAppend. First, check the last character of the path, and if it''s not a backslash then append the backslash. Then append the file spec.

[*] Keep in mind the operating systems you''re targeting. DX8.1, for instance, requires Win2k or Win98, so PathAppend will be there, so rewriting it is pointless.
---visit #directxdev on afternet <- not just for directx, despite the name

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.