Results 1 to 7 of 7

Thread: i need a code that will search for files

  1. #1

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461

    Cool i need a code that will search for files

    i need a code that will search for files in all drives and subdirs and useing wildcards.
    thx
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

  2. #2
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    Code:
    void dirclone(char *path)
    {
    char dirname[MAX_PATH];
    HANDLE fhwnd;
    WIN32_FIND_DATA FD;
    
    
    int i=0;
    
    SetCurrentDirectory(path);
    
    fhwnd = FindFirstFile("*.*", &FD);
    
    while(FindNextFile(fhwnd, &FD))
    {
    	if(
    		(FD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) &&
    		(strcmp(FD.cFileName, "..") && strcmp(FD.cFileName, "."))
    		)
    
    	{
    		GetCurrentDirectory(MAX_PATH, dirname);
    
    		if(strncmp(&dirname[strlen(dirname)-1], "\\", 1))
    			(void) strcat(dirname, "\\");
    
    		(void) strcat(dirname,FD.cFileName);
    		
    		cout<< dirname;
    
    				dirclone(dirname);
    		SetCurrentDirectory("..");
    	}
    }
    
    FindClose(fhwnd);
    }
    Matt

  3. #3

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461
    i dont want a clone!
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

  4. #4
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    try the code. It won't clone the files, i took that part out its just the name of he function.
    Matt

  5. #5

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461
    im new to C++, i dont know how to use it, i need the path to the file and some way of executing it, please walk me through it
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

  6. #6
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    ok if you have MSVC++, create a new console application.(Go to File -->new, then under projects tab select console application and name it.then say OK, next select the option next to "An empty project". Once you say ok, go to File -->New select the files tab and select source file.(name that as well). Ok now in your source file which will be up on the screen ready for text enter

    Code:
    #include <iostream.h>
    
    void dirclone(char *path)
    
    int main()
    {
    dirclone("C:\"); //enter any drive or path here.
    return 0;
    }
    
    
    void dirclone(char *path)
    {
    char dirname[MAX_PATH];
    HANDLE fhwnd;
    WIN32_FIND_DATA FD;
    
    
    int i=0;
    
    SetCurrentDirectory(path);
    
    fhwnd = FindFirstFile("*.*", &FD);
    
    while(FindNextFile(fhwnd, &FD))
    {
    	if(
    		(FD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) &&
    		(strcmp(FD.cFileName, "..") && strcmp(FD.cFileName, "."))
    		)
    
    	{
    		GetCurrentDirectory(MAX_PATH, dirname);
    
    		if(strncmp(&dirname[strlen(dirname)-1], "\\", 1))
    			(void) strcat(dirname, "\\");
    
    		(void) strcat(dirname,FD.cFileName);
    		
    		cout<< dirname;
    
    				dirclone(dirname);
    		SetCurrentDirectory("..");
    	}
    }
    
    FindClose(fhwnd);
    }
    Matt

  7. #7

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461
    oops i mean the path of the file that the search code find
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width