Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sample code for finding and copying files. 1

Status
Not open for further replies.

bigred925

MIS
Jul 6, 2001
15
US
I have been giving a mirgration project and have no experience with C++. This program has to find all the Word and excel docs and transfer them to another pc. Does anyone have any ideas or know of a good place to get info on this.

Thanks

Steve
 
check MSDN runtime library reference about "directory control", "file handling routines" and "system call" etc, you can get information about how to handle a drive, directory , how to "findfirst" and findnext" file
 
void traverse()
{
CFileFind finder;
BOOL bFilesExist = finder.FindFile("*.doc");

while(bFilesExist)
{
bFilesExist = finder.FindNextFile();

if(finder.IsDirectory())
continue;

// pseudo - code
Copy finder.GetFileName() to New Place
}

BOOL bWorking - finder.FindFile("*.*");

while(bWorking)
{
bWorking = finder.FindNextFile();

if(finder.GetFileName() != ".." &&
finder.GetFIleName() != ".")
{
if(finder.IsDirectory())
{
chdir( (LPCTSTR)(finder.GetFileName());
traverse();
}
}
}
chdir("..");
}

all this program needs is to be started in the directory you want it to run or to call "ChangeDirectory" or chdir before calling the function. I am pretty sure this will do the trick for you

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top