0

I want to write a simple batch file that can be run on a folder where the sub-folders have files that are not dos standard, the files to be deleted are of the form .,1 or .,2 (ie log.txt,1). I want all the ,1 ,2 ,3 files to be deleted but not the original log.txt files. What is the command structure for 'DEL' to allow this?

3
  • from reading your question I have an impression that you have file named log.txt,1 but in windows you can't have file named containing , Commented Apr 26, 2017 at 11:10
  • 2
    @npocmaka Why do you think so? echo:>"test.txt,1" Commented Apr 26, 2017 at 11:24
  • @LotPings - my mistake :-) Commented Apr 26, 2017 at 11:31

1 Answer 1

2

You only need to quote the file name with the comma.

@Echo off
For /F "delims=" %%A in (
  'Dir /B/S "*,*" ^| findstr ",[0-9][0-9]*$" '
) Do Echo Del "%%A"
  • The findstr will make shure there is a trailing comma with a number.
  • remove the echo in the last line if the output looks OK.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.