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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make searchs in c:\ directory...

Status
Not open for further replies.

Leibnitz

Programmer
Apr 6, 2001
393
CA
I want to create a little windows application not using MFC
that search the c:\ directory for files and folders and when it finds one of them automaticaly launch this file or folder.Any tips on how to proceed will be very apreciated.

:)
 
This bit of code is what I used to traverse subDirectorys and rename files. It can be modified to execute the program with a system call.

Code:
int RenameFiles(char* startingWith, char* renameTo, char* extension)
{
	CFileFind finder;	
	char renameFile[1028];
	char temp[1028];
	CString fileName;
	static int counter;

	sprintf(temp,"%s*.*",startingWith);
	bool bImagesExist = (bool)finder.FindFile(temp);


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

		if(finder.IsDirectory())continue;

		fileName = finder.GetFileName();

		sprintf(renameFile,"%s%d.%s",renameTo,counter++,extension);
		sprintf(temp,"Renaming %s to %s\n",(LPCTSTR)fileName,renameFile);
		cout<<temp;
		cout<<(rename((LPCTSTR) finder.GetFileName(),renameFile) ? &quot;COULD NOT RENAME&quot;:&quot;RENAMED&quot;)<<endl;
	}

	bool bWorking = finder.FindFile(&quot;*.*&quot;);
	while(bWorking)
	{
		bWorking = finder.FindNextFile();

		if(finder.GetFileName() != &quot;.&quot; && finder.GetFileName() != &quot;..&quot;)
		{
			if(finder.IsDirectory())
			{
				chdir((LPCTSTR)finder.GetFileName());
				RenameFiles(startingWith,renameTo,extension);
			}
		}
	}
	chdir(&quot;..&quot;);

	return counter;
	
}

Sorry if it is a bit jumbled...

Matt




 
Thanks for the code Zyrenthian i'll try to use it.

:)
 
Does any know how to search the c:\ root directory without using MFC ?

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top