0

I have and batch script to execute a command to delete several ext. Example:

set /p drive=Choose the letter of usb:
if %drive%== E goto E

Example (if you choose E)

E:
del /f /q E:\*.lnk *.inf *.init

But only delete the first one (*.lnk). The rest to redirect to the drive c (where i execute batch) Example:

Can't find C:\*.inf

I don't want to do this:

del /f /q E:\*.lnk
del /f /q E:\*.inf
del /f /q E:\*.init

How to fix it? Thanks

2

You can fairly quickly solve it by prefixing the other extensions like you did the first:

del /f /q E:\*.lnk E:\*.inf E:\*.init

Really though, instead of creating a block for each drive manually you could use your variable here to do the work for you:

set /p drive=Choose the letter of usb:

del /f /q %drive%:\*.lnk %drive%:\*.inf %drive%:\*.init
2
  • I have a aditional question: if exist %drive%:\data cd %drive%:\data (How to remove those within folders. Example del /f /q *.lnk *.inf inside data). Thanks
    – user290171
    Feb 25 '16 at 13:27
  • You can use Del /F/Q/S/A <path>\*.ext to delete all items matching *.ext in all sub folders starting at <path>
    – CoveGeek
    Mar 1 '16 at 17:48
0

Taz, I will borrow your answer to show the full example.

:TOP
set /p drive=Choose the letter of usb:
If "%drive%" EQU "" Goto :TOP
Set drive=%drive:~0,1%
del /f/q/s/a %drive%:\*.lnk %drive%:\*.inf %drive%:\*.init

Only accepts the first character typed and checks for no imput.

The /s will perform the check for the file in all sub folders starting from the path given. The /a will delete all file, even if they are hidden. Not 100% sure about read-only files though...

Quotes " are not used around parameters because the only user provided data is a single letter and there is no whitespace within the prewritten parameters.

0

Your Answer

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