Reputation: 15
If a tickbox is clicked on my application, all files in a specified folder having the same pre-dot name, (eg. TESTCRC32.xxx) will be re-named. If the filename is something else, (eg. Pic.jpg) this file will not be renamed.
How can I go about this? I was thinking a for loop...
void SecondDlg::OnTickBox()
{
// Add code here...
CString oldFile = myPath.Left(myPath.ReverseFind(_T('.')));
rename(oldFile, newFile);
}
Upvotes: 1
Views: 339
Reputation: 4395
You are doing wrong. lets take an example, Suppose myPath
is having path "C:\abc\xyz.bmp"
After this line:
CString oldFile = myPath.Left(myPath.ReverseFind(_T('.')));
Now:
oldFile = "C:\\abc\\xyz"; // extension removed
At last you are calling rename
rename(oldFile, newFile); //you can use myPath instead of oldFile
As oldFile = "C:\abc\xyz";
and which is not the correct path, so it is not renamimg the file.
you should pass full path of the file(C:\abc\xyz.bmp).
Upvotes: 1