2

How to delete files and folders in the folder?

Eg. "cat" folder. In the folder existing (3 folders and 5 mp3s and 4 docxs)files. I delete with this codes:

       del /f /s /q c:\cat


       rd /s /q c:\cat

del..... it delete mp3, docx but not del 3 folders. It delete files in the 3 folder.it not del 3 folders.

rd...... it delete "cat" folder, I don't del "cat" folder. I want is to delete files and folders in the "cat" folder.

3 Answers3

2
 for /d %%a in (c:\cat\*) do echo rd /s /q "%%~a"

Removes (deletes) a directory.

RMDIR [/S] [/Q] [drive:]path RD [/S] [/Q] [drive:]path

/S      Removes all directories and files in the specified directory
        in addition to the directory itself.  Used to remove a directory
        tree.

/Q      Quiet mode, do not ask if ok to remove a directory tree with /S

Endoro
  • 37,015
  • 8
  • 50
  • 63
1
rd /s /q c:\cat
md c:\cat

(as you don't need no files or folders inside you can delete the folder and re-create it)

Looking for a better way...EDIT:(I think is not possible without listing items)

for /f "delims=" %%a in ('dir /b  "c:\cat"') do ( 
  rd /s /q "%~a" >nul 2>&1||del /q /f "%~a" >nul 2>&1
)
npocmaka
  • 55,367
  • 18
  • 148
  • 187
0
( pushd "c:\cat" && rmdir . /s /q ) & popd

Change to the desired directory.

If that do work, then remove current directory. This will delete all inside the current directory, but, as the current directory is in use, it can't be deleted.

Once finished, return to previous directory

MC ND
  • 69,615
  • 8
  • 84
  • 126