Deleting contents of a directory

  • Thread starter Thread starter Gabriele O.
  • Start date Start date
G

Gabriele O.

Hi all,
How can I delete all files and subdirectories from a given directory,
by command line?

Thanks in advance.
 
Gabriele O. said:
Hi all,
How can I delete all files and subdirectories from a given directory,
by command line?

Thanks in advance.

rd /s /q c:\SomeFolder
 
rd /s /q c:\SomeFolder

Thanks for your answer, but this would delete the directory itself. I
know then i could write "md SomeFolder", but that can't be done
because I'm on a fileserver that won't allow that. I'd like to delete
the whole content of the folder without deleting the folder itself.
If I remember well, up to win98 there was a "deltree" command, so it
could be used "deltree /y *.*". But now on win2000 this can't be done.
 
Hello Jerold!

See tip 617 in the 'Tips & Tricks' at http://www.jsiinc.com
0617 » How do I remove all files and sub-directories from a folder,
without removing the folder?

In this tip is written:

*******************************************************
* @echo off
* pushd %1
* del /q *.*
* for /f "Tokens=*" %%i in ('dir /B') do rd /s /q "%%i"
* popd
*******************************************************

This works fine with Windows 2000/XP

*******************************************************
* To delete all the files and sub-directories in <Drive:>\My Test Folder,
type:
*
* DELTREE "<Drive:>\My Test Folder"
*******************************************************

Deltree isn't a recognized command in Windows 2000, so in my opinion the
command should also be "del", or specify for witch operating Systems this
tip work.

Thanks.
 
Try This in a Batch File

del c:\foldername\. /s /f /q

Where folder name is put name of your folder.....

Hope all goes well
 
Try This - This will delete all files but not Folder it's
self

del c:\foldername\. /s /f /q

Where foldername is replace with your folder name...

Hope this helps...
 
Peter Forster said:
In this tip is written:
*******************************************************
* @echo off
* pushd %1
* del /q *.*
* for /f "Tokens=*" %%i in ('dir /B') do rd /s /q "%%i"
* popd
*******************************************************
This works fine with Windows 2000/XP
*******************************************************
* To delete all the files and sub-directories in <Drive:>\My Test Folder,
type:
*
* DELTREE "<Drive:>\My Test Folder"
*******************************************************
Deltree isn't a recognized command in Windows 2000, so in my opinion the
command should also be "del", or specify for witch operating Systems this
tip work.

Deltree.bat is the suggested name of the batch file containing the lines
above.
 
Gary Smith said:
Deltree.bat is the suggested name of the batch file containing the lines
above.

Is it a good idea to give a batch file the same name as
a well-known Win98 executable? It seems this could
easily lead to confusion, as is apparent in this thread.
 
Pegasus \(MVP\) said:
Is it a good idea to give a batch file the same name as
a well-known Win98 executable? It seems this could
easily lead to confusion, as is apparent in this thread.

In this case, I think it is. The idea is to create a batch file which
provides the functionality of deltree.exe. Deltree.bat (or deltree.cmd)
is the obvious thing to call it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top