Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I search files use
SearchFiles("C:\\Users\\Admin\\Desktop\\*.txt", DoSomething, TRUE);


What I have tried:

void DoSomething(LPCTSTR lpszFileName)
{
	string z = random_string(5);
LPTSTR x = new TCHAR[z.size() + 1];
    //MessageBox(NULL, lpszFileName, "Find File", MB_OK | MB_APPLMODAL);
	CopyFile(lpszFileName,	strcpy(x, z.c_str()),true);
	MessageBox(NULL, strcpy(x, z.c_str()), "Find File", MB_OK | MB_APPLMODAL);
}

CopyFile is
BOOL WINAPI CopyFile(LPCTSTR lpExistingFileName,LPCTSTR lpNewFileName,BOOL bFailIfExists);

It great work - copy to my program random name files
1)But i wont using original name files to my prog!
CopyFile(lpszFileName,lpszFileName,true);

so it dont copy idk why!
Posted
Updated 22-May-18 0:10am
v2
Comments
Peter_in_2780 20-May-18 6:17am    
So you want to copy an existing file onto itself, and you have set FailIfExists to true....

1 solution

your code is a bit messy
C++
strcpy(x, z.c_str());// fill x
CopyFile(lpszFileName, x, true);//use x

This should work a bit, but copy the file in the app directory. Use a complete path for better results.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900