Dear all
what's the function name in c++ if i want use this function to delete my file
Printable View
Dear all
what's the function name in c++ if i want use this function to delete my file
DeleteFile
I love M$ for this, it's so intuitive. :cool:Quote:
Originally Posted by GCDEF
also _wremove()
Kuphryn
that's best oneQuote:
Originally Posted by kuphryn
if( remove( "test.dat" ) == -1 )
perror( "Could not delete 'test.dat'" );
else
printf( "Deleted 'test.dat'\n" );
system("pause");
Well, I would still go for DeleteFile, since it's underlaying WinAPI.
I would use ::SHFileOperation() with FO_DELETE since DeleteFile()/ remove() would fail to delete read only file. :)
CheersCode:SHFILEOPSTRUCT fo={0};
fo.wFunc = FO_DELETE;
fo.pFrom = "C:\\delme.txt";
fo.fFlags = FOF_NOCONFIRMATION|FOF_SILENT;
::SHFileOperation(&fo);
Hehe, the beauty of the IT world: event the simplest problem has 5 solutions that do not work 100% of the time and 1 that works for the time being but you never now in the future. :) These are the moments I feel the IT really makes the world a better place to live. ROFLMAO
:thumb:Quote:
Originally Posted by PadexArt
unlink() - would be another option :)
how about if i want to delete one of folder all file , what's method i can do it
Quote:
Originally Posted by PadexArt
I Love to use WinAPIs DeleteFile..
Hey PadexArt here I got you a more joy..... I got one more solution...
CFile::Remove(fileName)....
;)..
so now will u feel IT makes the BEST place.......
ha ha ha..
Does (or can) the folder contain folders?Quote:
Originally Posted by roger5089
Quote:
Originally Posted by roger5089
go through the below link...
Hope it helps you.
http://www.codeguru.com/forum/showthread.php?t=239271
One more:
Regards,Code:system("del myfile.txt");
Paul McKenzie
No, It is the same as DeleteFile. Just look at the source code:Quote:
Originally Posted by dwurity
:D :DQuote:
Code:void PASCAL CFile::Remove(LPCTSTR lpszFileName)
{
if (!::DeleteFile((LPTSTR)lpszFileName))
CFileException::ThrowOsError((LONG)::GetLastError());
}
Use ::SHFileOperation() as I suggested in my previous post, it will also delete folder and all it subfolders.Quote:
Originally Posted by roger5089
Cheers
thank's you suggestionQuote:
Originally Posted by VictorN
the problem is how can i 'DeleteDirectory' 'const char [8]' convert 'LPCTSTR'
Code:
bool DeleteDirectory(LPCTSTR lpszDir, bool noRecycleBin = true)
{
int len = _tcslen(lpszDir);
TCHAR *pszFrom = new TCHAR[len+2];
_tcscpy(pszFrom, lpszDir);
pszFrom[len] = 0;
pszFrom[len+1] = 0;
SHFILEOPSTRUCT fileop;
fileop.hwnd = NULL; // no status display
fileop.wFunc = FO_DELETE; // delete operation
fileop.pFrom = pszFrom; // source file name as double null terminated string
fileop.pTo = NULL; // no destination needed
fileop.fFlags = FOF_NOCONFIRMATION|FOF_SILENT; // do not prompt the user
if(!noRecycleBin)
fileop.fFlags |= FOF_ALLOWUNDO;
fileop.fAnyOperationsAborted = FALSE;
fileop.lpszProgressTitle = NULL;
fileop.hNameMappings = NULL;
int ret = SHFileOperation(&fileop);
delete [] pszFrom;
return (ret == 0);
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// 初始化 MFC 並於失敗時列印錯誤
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: 配合您的需要變更錯誤碼
_tprintf(_T("嚴重錯誤: MFC 初始化失敗\n"));
nRetCode = 1;
}
else
{
// TODO: 在此撰寫應用程式行為的程式碼。
DeleteDirectory("d:\\Test", false);
}
return nRetCode;
}
Typecast it,
Code:DeleteDirectory((LPCTSTR) _T("d:\\Test"), false);
Thank's your help , but i found the problem of this function , which is delete all folder data , not just delete that folder insite data?
Your question is not clear; please explain what exactly you want to achieve.Quote:
Originally Posted by roger5089
Cheers