deleting all files from a folder
-
No problem we can use from a
Do while
and yes its right.WIN32_FIND_DATA find; SetCurrentDirectory("c:\\temp"); HANDLE handle=FindFirstFile("*.mdb",&find); do DeleteFile(find.cFileName);//or you can use from //SHFileOperation(...); while(FindNextFile(handle,&find)!=0); FindClose(handle);
_**
**_
WhiteSky
This is the program that I tried.
#include "afxdisp.h"
void main()
{WIN32\_FIND\_DATA find; char aExePath\[\_MAX\_PATH\]; char aDrive\[\_MAX\_DRIVE\]; char aDir\[\_MAX\_DIR\]; CString aPath; ::GetModuleFileName( AfxGetInstanceHandle(),aExePath,sizeof(aExePath)); \_splitpath(aExePath,aDrive,aDir,NULL,NULL); aPath.Format("%s%s",aDrive,aDir); aPath = aPath + "sbh\_store"; SetCurrentDirectory(aPath); HANDLE handle=FindFirstFile("\*.mdb",&find); do DeleteFile(find.cFileName); while(FindNextFile(handle,&find)!=0); FindClose(handle);
}
Here I get the error
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadexWhen I comment out
CString aPath; ::GetModuleFileName( AfxGetInstanceHandle(),aExePath,sizeof(aExePath));
I do not get theunresolved external symbol
error. I guess I am missing something. Please can you tell me what I am not doing right. Have I missed out a header? -- modified at 5:40 Friday 18th August, 2006_
Fortitudine Vincimus!_
-
You can use
SHFileOperation()
which takes wildcards.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
I tried using SHFileOperation. But the program is crashing. This is what I did:
SHFILEOPSTRUCT del;
del.hwnd = NULL; del.wFunc = FO\_DELETE; del.pFrom = "C:\\\\temp\\\\\*.mdb"; del.fFlags = FOF\_FILESONLY; SHFileOperation(&del);
Something is wrong here. I tried searching the net, but I am not able to figure it out. Please can you help me. Thanks.
_
Fortitudine Vincimus!_
-
This is the program that I tried.
#include "afxdisp.h"
void main()
{WIN32\_FIND\_DATA find; char aExePath\[\_MAX\_PATH\]; char aDrive\[\_MAX\_DRIVE\]; char aDir\[\_MAX\_DIR\]; CString aPath; ::GetModuleFileName( AfxGetInstanceHandle(),aExePath,sizeof(aExePath)); \_splitpath(aExePath,aDrive,aDir,NULL,NULL); aPath.Format("%s%s",aDrive,aDir); aPath = aPath + "sbh\_store"; SetCurrentDirectory(aPath); HANDLE handle=FindFirstFile("\*.mdb",&find); do DeleteFile(find.cFileName); while(FindNextFile(handle,&find)!=0); FindClose(handle);
}
Here I get the error
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadexWhen I comment out
CString aPath; ::GetModuleFileName( AfxGetInstanceHandle(),aExePath,sizeof(aExePath));
I do not get theunresolved external symbol
error. I guess I am missing something. Please can you tell me what I am not doing right. Have I missed out a header? -- modified at 5:40 Friday 18th August, 2006_
Fortitudine Vincimus!_
see this solution
Prasad Notifier using ATL
-
You can use
SHFileOperation()
which takes wildcards.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
I tried using SHFileOperation. But the program is crashing. This is what I did:
SHFILEOPSTRUCT del;
del.hwnd = NULL; del.wFunc = FO\_DELETE; del.pFrom = "C:\\\\temp\\\\\*.mdb"; del.fFlags = FOF\_FILESONLY; SHFileOperation(&del);
Something is wrong here. I tried searching the net, but I am not able to figure it out. Please can you help me. Thanks.
_
Fortitudine Vincimus!_
you need to set
del.pTo
,too. i.e. set it to NULL if you are not using it. code will be,SHFILEOPSTRUCT del;
del.hwnd = NULL;
del.wFunc = FO_DELETE;
del.pFrom = "C:\\temp\\*.mdb";
del.fFlags = FOF_FILESONLY;
del.pTo = NULL;
SHFileOperation(&del);Oh ! you got it right already. :) -- modified at 5:59 Friday 18th August, 2006
Prasad Notifier using ATL
-
see this solution
Prasad Notifier using ATL
-
Hi, I have developed an application which creates
.mdb
files in a specific folder namedstore
. This folder is created during installation. But when the program is uninstalled, since there are additional(new) files in the folderstore
, the folder does not get deleted from the computer. I thought, maybe I should create a small.exe
program that deletes all the.mdb
files from thestore
folder before the uninstall is run. The problem here is that I do not know the names of the files in the folder. Is there anyway or any function by which I can find and delete all.mdb
files from the folderstore
? Thanks._
Fortitudine Vincimus!_
hi, i don't want to give you an answer, instead i would like to ask about how you can make your app create an mdb file. because this is what i trying to do right now. if you don't mind, would you share me you little secret? thanks in advance. cheers -- modified at 10:25 Friday 18th August, 2006
-
Is your problem solve
_**
**_
WhiteSky
-
hi, i don't want to give you an answer, instead i would like to ask about how you can make your app create an mdb file. because this is what i trying to do right now. if you don't mind, would you share me you little secret? thanks in advance. cheers -- modified at 10:25 Friday 18th August, 2006
Hello, I use DAO to make the connection. There are some really nice samples that come in msdn. I wrote my own little class to do the stuff taking help from the samples. Here is the database creation part. My database needed to be locked with a password.
//////////////////////////////////////////////////////
/////////********* CREATE DATABASE ***********///////////////////////////void CDBcreate::CreateDatabase(CString m_strDBName)
{int dwOptions =0;
dwOptions |=dbVersion30;//Release table if selected
if (m_pTableDef)
{
m_pTableDef->Close();
delete m_pTableDef;
m_pTableDef = NULL;
}//close database if open
if (m_pDatabase)
{
m_pDatabase->Close();
delete m_pDatabase;
m_pDatabase=NULL;
}//create new database
m_pDatabase = new CDaoDatabase;
m_pDatabase->Create(m_strDBName, dbLangGeneral,dwOptions);CString strConnect( _T( ";pwd=" ) );
COleVariant NewPassword( "password", VT_BSTRT ),OldPassword( "", VT_BSTRT );
DAO_CHECK( m_pDatabase->m_pDAODatabase->NewPassword( V_BSTR( &OldPassword ),
V_BSTR( &NewPassword ) ) );
m_bOpen=TRUE; // flag of currently open table}
/////////********* END CREATE DATABASE ***********///////////////////////////
_
Fortitudine Vincimus!_
-
Is your problem solve
_**
**_
WhiteSky
Yes. Changing the settings helped. But there is something I do not understand. I used
::GetModuleFileName( AfxGetInstanceHandle(),aExePath,sizeof(aExePath));
in my application using mfc. There I had no problem. But in the C++ program that I wrote to delete files form a folder,AfxGetInstanceHandle()
was causing assersion failure. I could'nt figure out why. When I changed it to NULL>::GetModuleFileName( NULL,aExePath,sizeof(aExePath));
it worked fine. Why?_
Fortitudine Vincimus!_