Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Stevieboy

how do I use a variable for a file search

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

Hi, how would I use a variable to do A file search? I''ve included some of the code I''ve been learning from below (that actually works how it is), in another tutorial I read it says where the "*.*" , is you can use a variable instead. // // DirWalk.C // // By Ciro Sisman Pereira // CiroSP@aol.com // #include <windows.h> #include <stdio.h> #include <string.h> #include <stdlib.h> void fDirWalk(char *); void displayTree(int, char *); //------------------------------------------------ void main( int pcount, char *ptext[] ) //------------------------------------------------ { if ( pcount < 2 ) { printf("\\"); fDirWalk( "\\" ); } else { printf(ptext[1]); fDirWalk( ptext[1] ); } } //------------------------------------------------ void fDirWalk(char *_current) //------------------------------------------------ { char DirName[MAX_PATH]; HANDLE Hnd; WIN32_FIND_DATA WFD; static int _dlevel = 0; // Set the new current directory SetCurrentDirectory( _current ); // Starts the search Hnd = FindFirstFile( "*.*", &WFD ); // loop to get all inside the current directory while ( FindNextFile( Hnd, &WFD ) ) { // If it is a real directory if ( ( WFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) && ( strcmp(WFD.cFileName, "..") && strcmp(WFD.cFileName, ".") ) ) { // Get the current directory GetCurrentDirectory( MAX_PATH, DirName ); // Put a "\" if necessary if ( strncmp( &DirName[strlen(DirName)-1], "\\", 1 ) ) (void) strcat( DirName, "\\" ); // Create a new path (void) strcat( DirName, WFD.cFileName ); // Add 1 to level counter _dlevel++; // Show the new directory displayTree( _dlevel, WFD.cFileName ); // Make a new call to itself fDirWalk( DirName ); // Go back one level SetCurrentDirectory( ".." ); // Subtracts 1 to level counter _dlevel--; } } // End while // End the search to this call (void) FindClose( Hnd ); return; } //------------------------------------------------ void displayTree(int _dnumber, char *_dname) //------------------------------------------------ { char _txt[128]; int _c = 0; (void) memset( _txt, 0x00, sizeof(_txt) ); (void) memset( _txt, '' '', _dnumber * 3 ); for ( _c = 0; _c < _dnumber * 3; _c+=3 ) _txt[_c] = ''|''; _txt[_c-1] = _txt[_c-2] = ''_''; printf("\n%s%s", _txt, _dname ); fflush(stdout); }

Share this post


Link to post
Share on other sites
Advertisement

  • 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!