Click to See Complete Forum and Search --> : i need a code that will search for files
Cmdr0Sunburn
Jul 26th, 2001, 02:29 PM
i need a code that will search for files in all drives and subdirs and useing wildcards.
thx
MPrestonf12
Jul 26th, 2001, 03:28 PM
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);
}
Cmdr0Sunburn
Jul 26th, 2001, 03:47 PM
i dont want a clone!
MPrestonf12
Jul 27th, 2001, 01:52 PM
try the code. It won't clone the files, i took that part out its just the name of he function.
Cmdr0Sunburn
Jul 27th, 2001, 05:06 PM
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 ;)
MPrestonf12
Jul 28th, 2001, 05:53 PM
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
#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);
}
Cmdr0Sunburn
Jul 28th, 2001, 07:59 PM
oops i mean the path of the file that the search code find
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.