How to search and delete a file
-
Hi guys i am new in MFC i want to know how to search for a specific file and delete it. ?? So please help me. I didn't find any any function for deleting like rename(brfore,after) for renaming a file or folder name.
Regards: Xohaib Shirani
Use FindFirstFile()/FindFirstFileEx() to find a file with a specifc name. DeleteFile() to delete it
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
Hi guys i am new in MFC i want to know how to search for a specific file and delete it. ?? So please help me. I didn't find any any function for deleting like rename(brfore,after) for renaming a file or folder name.
Regards: Xohaib Shirani
If you already know the path of the file to be deleted, then you don't have to search for it. You can use
PathFileExists()
function to see if the file exists. you can also use the functionPathIsDirectory()
to see if given path is that of a directory or a file. The below code snippet might make the point clear to you.TCHAR szFilePath[MAX_PATH];
_tcscpy(szFilePath, _T("C:\\file.txt") );//Check if the file with the given path really exists and is not a directory.
if(PathFileExists(szFilePath) && !PathIsDirectory(szFilePath))
DeleteFile(szFilePath);//delete the file 'C:\file.txt'Regards, Vijay.
-
If you already know the path of the file to be deleted, then you don't have to search for it. You can use
PathFileExists()
function to see if the file exists. you can also use the functionPathIsDirectory()
to see if given path is that of a directory or a file. The below code snippet might make the point clear to you.TCHAR szFilePath[MAX_PATH];
_tcscpy(szFilePath, _T("C:\\file.txt") );//Check if the file with the given path really exists and is not a directory.
if(PathFileExists(szFilePath) && !PathIsDirectory(szFilePath))
DeleteFile(szFilePath);//delete the file 'C:\file.txt'Regards, Vijay.
-
error C2065: 'PathFileExists' : undeclared identifier error C2065: 'PathIsDirectory' : undeclared identifier
Regards: Xohaib Shirani