45

This code that does not work:

@echo off

if exist output @set /p checkdir= Output directory found. Do you wish to overwrite it?:

if  /I %checkdir% == Y  deltree /s /output 
pause
misctp asdas
  • 973
  • 4
  • 13
  • 35
  • 1
    what problems have you found? DELTREE is not present in many current versions of Windows. Is root the current dir? – PA. Oct 24 '11 at 07:44

1 Answers1

100

You were looking for this command:

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

In your case just use /S ,it will delete the whole directory tree by first asking the user if it should proceed, i.e.- displaying the following output to the screen:

"folderName, Are you sure (Y/N)?"

where folderName is the name of the folder (and its sub-folders) you wish to remove.

Tested on Windows 7, 64 bit.

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
weberik
  • 2,636
  • 1
  • 18
  • 11
  • RD works fine. Make sure to add the absolute path or "cd" to the parent directory and just pass the name of the subfolder. – Marcell Mar 29 '19 at 07:32