Scripts Thread, Empty the contents of a folder in Coding and Web Development; Please can somone isnstruct me on a script that will empty the contents of a folder but not the folders ...
1. ## Empty the contents of a folder

Please can somone isnstruct me on a script that will empty the contents of a folder but not the folders itself.

Cheers

2. What language?

4. Making the assumption we're talking about a windows machine, then try:

del d:\folders-you-want-to-empty-just-files-from\*.* /s /f /q

where d: etc is the location of the root folder you want to clear... Think it's v.similar in Swahili!

5. .bat wouls be best please

i can't get this one to work

del C:\New Folder\*.* /s /f /q

Z

6. Try enclosing the path with quotes - spaces confuses CMD.exe.

7. Ok thanks i will give that ago tomorrow.

Z

8. Hi

the command that tonyd posted will only delete files, i need it to delete folders as well.

Z

9. Originally Posted by FN-Greatermanchester
Please can somone isnstruct me on a script that will empty the contents of a folder but not the folders itself.

Cheers
Originally Posted by FN-Greatermanchester
Hi

the command that tonyd posted will only delete files, i need it to delete folders as well.

Z

Sorry Z, but I'm confused - you OP states you only want to delete the files, which means tonyd's Command works.. (deletes all files but no folders)

But then you say you want to delete the folders too?

If you want to delete all subfolders, but not the root try this:
Code:
@echo off
pushd %1
del /q *.*
for /f "Tokens=*" %%G in ('dir /B') do rd /s /q "%%G"
popd
taken from here

10. Still haven't got round to doing this

"Sorry Z, but I'm confused - you OP states you only want to delete the files, which means tonyd's Command works.. (deletes all files but no folders)"

In my post it says delete the contents of a folder but not the folder itself, sorry for the confusion.

11. Here you go. Something to remove all files and subfolders from a given folder. Just give it the path as "X:\whatever\foo\bar" and away you go. It was done in 5 minutes flat so it's not my finest code. It's quite safe though, it won't go and trash your folders. Promise. See if it does the trick.

12. ## Thanks to bizzel from:

FN-GM (12th March 2008)

Z

14. Just uploaded it now. Needs .Net 2.0 to be installed btw. You'll probably have it already.

15. ## Thanks to bizzel from:

FN-GM (12th March 2008)

16. Thanks alot mate, will take a look at that tomorrow.

Z

SHARE: