0
@echo off
FOR %%P IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO (
  IF EXIST %%P:\nul (
cls
SET /a count=%count%+1
dir /s /b %%P:\ |find /c "\" >NUMfiles.max
set /p "counter%count%"=<NUMfiles.max

del %%P:\apple.doc
del %%P:\orange.doc

dir /s /b %%P:\ |find /c "\" >NUMfiles.max
set /p "counter%count%%%P"=<NUMfiles.max
set /a "counter%%P"="counter%count%" - "counter%count%%%P"

  )
)

set /a finalcount="countera + counterb + counterc + counterd + countere +         counterf + counterg + counterh + counteri + counterj + counterk + counterl + counterm + countern + countero + counterp + counterq + counterr + counters + countert + counteru + counterv + counterw + counterx + countery + counterz"
ECHO Total Number of deleted files: %finalcount%

The program is scanning each and every drive to delete apple.doc & orange.doc and after finished deleted all files from all drives it will give me the total result of how many total files deleted.

Please help.

  • It is giving me an error "The Syntax of the Command is Incorrect" – MaxiExtreme Mar 03 '16 at 11:08
  • 2
    the famous [delayed expansion trap](http://stackoverflow.com/a/30284028/2152082)... – Stephan Mar 03 '16 at 11:18
  • Possible duplicate of [Combining All MP4s in Directory with ffmpeg](http://stackoverflow.com/questions/30282784/combining-all-mp4s-in-directory-with-ffmpeg) – Mast Mar 03 '16 at 11:28

1 Answers1

0

You are missing the good old SETLOCAL EnableDelayedExpansion. When working with variables which are modified inside FOR loops, you always have to add SETLOCAL EnableDelayedExpansion at the beginning of your script. Further you have to address your loop-modified variables with !var! instead of %var%. That should be it.

MichaelS
  • 5,941
  • 6
  • 31
  • 46
  • Can you help me revise my code instead to for me to fully understand because i am still having syntax error... Hope it's ok.... – MaxiExtreme Mar 03 '16 at 11:30
  • No need i got it working. the syntax error was coming from "" in the set command. thank you so much for this!!! – MaxiExtreme Mar 03 '16 at 12:08