0

I think this should be rather simple but I want to delete all the files that are stated in for example: C:\TEST but I want to leave the files that are located in subdirectories of this folder. For example files in the folder: C:\TEST\Backup should not be deleted.

When using the following batch command all the files get deleted including those located in sub directories but it leaves the folder:

DEL /S C:\TEST\ /q

Does anyone know the command that I need?

1

You can use:

DEL /Q C:\TEST\*.*

It will delete all files in C:\TEST. Wildcard *.* selects only files.

If you need a prompt before deleting a file remove /Q from the command.

Syntax:

DEL|ERASE [options] [/A:file_attributes] files_to_delete

Options:

  /P  Give a Yes/No Prompt before deleting. 
  /F  Ignore read-only setting and delete anyway (FORCE) 
  /S  Delete from all Subfolders (DELTREE)
  /Q  Quiet mode, do not give a Yes/No Prompt before deleting.

  /A  Select files to delete based on file_attributes
        file_attributes:
          R  Read-only    -R  NOT Read-only
          A  Archive      -A  NOT Archive
          S  System       -S  NOT System
          H  Hidden       -H  NOT Hidden
          I  Not content indexed  -I  content indexed files
          L  Reparse points       -L  NOT Reparse points

          X  No scrub file attribute  -X  Scrub file attribute   (Windows 8+)
          V  Integrity attribute      -V  NO Integrity attribute (Windows 8+)

Source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.