BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

deleting files in a directory

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
JoeBlack
Guest





PostPosted: Fri May 06, 2005 2:02 pm    Post subject: deleting files in a directory Reply with quote



Hi all,

I have a function, as follows:

void __fastcall TMainForm::DeleteAllFiles(void)
{
char szb[500];
char szc[500];

SHFILEOPSTRUCT shfo;
shfo.hwnd = GetDesktopWindow();
shfo.wFunc = FO_DELETE;
wsprintf(szb,"%s%c%c",DirList->Strings[HOMENETWORK],0,0);
shfo.pFrom = &szb[0];
wsprintf(szc,"%s%c%c",DirList->Strings[HOMELOCAL],0,0);
shfo.pTo = &szc[0];
shfo.fFlags = FOF_NOCONFIRMATION | FOF_ALLOWUNDO ;
SHFileOperation(&shfo);
}

DirList is a string list with directory names in it, the problem is the line

wsprintf(szb,"%s%c%c",DirList->Strings[HOMENETWORK],0,0);

copies a directory name, say "c:\temp1" into the pFrom string, when I
call the SHFileOperation it deletes the "c:\temp1" directory. What I
would like to do is delete all its contents but leave the directory intact.

I could generate a list of all the files and folders in the directory
and delete them individually but I was wondering if there was an easier
way to do it, i.e. by modifying the code presented above.

Any thoughts

Thanks

Joe
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri May 06, 2005 5:39 pm    Post subject: Re: deleting files in a directory Reply with quote




"JoeBlack" <JoeBlack (AT) newsgroups (DOT) nospam> wrote


Quote:
the problem is the line

wsprintf(szb,"%s%c%c",DirList->Strings[HOMENETWORK],0,0);

copies a directory name, say "c:\temp1" into the pFrom string,
when I call the SHFileOperation it deletes the "c:\temp1" directory.
What I would like to do is delete all its contents but leave the
directory intact.

Have youtried specifying a file mask, ie: "c:\temp\*.*" ? Have you tried
applying the FOF_FILESONLY flag?


Gambit



Back to top
JoeBlack
Guest





PostPosted: Mon May 09, 2005 8:19 am    Post subject: Re: deleting files in a directory Reply with quote



Remy Lebeau (TeamB) wrote:
Quote:
"JoeBlack" <JoeBlack (AT) newsgroups (DOT) nospam> wrote in message
news:427b78e2 (AT) newsgroups (DOT) borland.com...


the problem is the line

wsprintf(szb,"%s%c%c",DirList->Strings[HOMENETWORK],0,0);

copies a directory name, say "c:\temp1" into the pFrom string,
when I call the SHFileOperation it deletes the "c:\temp1" directory.
What I would like to do is delete all its contents but leave the
directory intact.


Have youtried specifying a file mask, ie: "c:\temp\*.*" ? Have you tried
applying the FOF_FILESONLY flag?


Gambit


Remy,


Many thanks, this has sorted my problem.

Joe

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.