Skip to content
⌘ NSIS Forum Archive

deleting contents of folder

8 posts

kristjan84#

deleting contents of folder

Hi,

How do I remove the contents of a folder, without removing the folder itself.
kristjan84#
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
kristjan84#
Does anyone know how to do this?

Just trying to empty a directory, with deleting the folder
Animaether#
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.
MSG#
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...
kristjan84#
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.