Archive: deleting contents of folder


deleting contents of folder
Hi,

How do I remove the contents of a folder, without removing the folder itself.


Use Delete Folder\*.*?

Stu


hi

thanks for your reply

i tried this, but this also removes the folder,

for example, i want to remove all files and folders in the following folder:

c:\temp\files\

but i dont want to remove the 'files' folder, i just want to keep that empty


Does anyone know how to do this?

Just trying to empty a directory, with deleting the folder


Simplest would be completely removing the folder and then recreating it.


o_O

delete "c:\temp\test\*.*"

Should most definitely *not* remove the 'test' folder itself, just the files therein. If you are seeing different behavior, that might be good to know.

The only alternative I can think of is using FindFirst, FindNext, FindClose to loop over the files in the folder and deleting them 1-by-1.

Deleting the folder itself and re-creating it may not always be an option if there's (NTFS) permissions / settings on the folder that are a hassle (if at all possible) to re-setup.

I'm thinking maybe the folder gets deleted because it's in Temp? That's assuming C:\temp is the Temp folder. At least I don't see any other reason why it'd disappear...


thanks for the replies

I think I will try going for the FindFirst, FindNext, FindClose method, since there are folders inside the directory that I want to clean, and Delete C:\folder\folder\*.* does not remove any folders that are inside the directory, only files.