Looping batchfile with counter

BondUniverse

Ok, I know the loop part is invalid, but hopefully helps give an idea of what I want to do. Ultimately, I want to get prompted for the 3 values (commented out the prompts for now and hard coding for ease of testing), then I want it to run through the loop once per CD (so 8 times in this example). I want it to name the .mp3 file with an incrementing CD#... CD1, CD2, CD3, etc. If anyone has any improvements, those are welcome too! I'm posting my full code here to share with the community.

@ECHO OFF

REM set /p BookName="Book Name:  "
REM set /p AuthorName="Author Name:  "
REM set /p CDNumber="Number of CDs:  "

set BookName=Victory and Honor
set AuthorName=W.E.B. Griffin
set CDNumTot=8

set PathName=C:\Rip\%AuthorName%\%BookName%
mkdir "C:\Rip\%AuthorName%\%BookName%\"
REM cd C:\Program Files (x86)\freac

ECHO CD Count:  %CDNumTot%

FOR /L %%N IN (1, 1, %CDNumTot%) DO (
  Set FileName=%PathName%\%BookName% CD%%N.mp3
  ECHO Filename:  %FileName%
  ECHO\
  ECHO Ripping CD# %%N...
  ECHO freaccmd -track all -o %FileName%
  ECHO CLS
  ECHO\
  ECHO\
  set /A NextCD=%%N
  ECHO Next:  %NextCD
  ECHO Please Eject CD and insert next CD# %NextCD%...
  pause
)

Final version of this code (WORKING thanks to @JoeNahmias):

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

set /p BookName="Book Name:  "
set /p AuthorName="Author Name:  "
set /p CDNumTot="Total number of CDs:  "

set PathName=C:\Rip\%AuthorName%\%BookName%


FOR /L %%N IN (1, 1, %CDNumTot%) DO (
  cls
  ECHO\
  ECHO Please insert CD# %%N...
  ECHO\
  pause
  SET FileName=%PathName%\%BookName% CD%%N.mp3
  cls
  ECHO\
  ECHO Ripping CD# %%N...
  ECHO\
  "C:\Program Files (x86)\freac\freaccmd" -track all -o "!FileName!"
  REM You need the id3 executable downloaded/installed for the next line:
  REM id3 -l "!BookName!" -a "!AuthorName!" -n %%N "!FileName!"
  rundll32 user32.dll,MessageBeep -1
  ECHO\
  ECHO Please eject CD# %%N...
  pause
)

cls
ECHO\
ECHO DONE!
pause
JoeNahmias

You want the FOR /L command. For example:

C:\>SET num=7
C:\>FOR /L %I IN (1, 1, %num%) DO @echo %I
1
2
3
4
5
6
7

Note that you have to double the lead percent sign in a batch file. So, for your CD ripping loop:

FOR /L %%n IN (1, 1, %CDNumTot%) DO (
  SET FileName=%PathName%\%BookName% CD %%n.mp3
  ...
)

If you're having difficulty, try putting the following in a batch file and seeing if you get it working:

@ECHO OFF
SET num=7
FOR /L %%I IN (1, 1, %num%) DO @echo %%I

Try this for a complete solution:

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

REM set /p BookName="Book Name:  "
REM set /p AuthorName="Author Name:  "
REM set /p CDNumTot="Total number of CDs:  "

set BookName=Victory and Honor
set AuthorName=W.E.B. Griffin
set CDNumTot=8

set PathName=C:\Rip\%AuthorName%\%BookName%
REM mkdir "C:\Rip\%AuthorName%\%BookName%\"
REM cd C:\Program Files (x86)\freac

ECHO CD Count:  %CDNumTot%

FOR /L %%N IN (1, 1, %CDNumTot%) DO (
  ECHO Please Eject CD and insert next CD# %%N...
  pause
  SET FileName=%PathName%\%BookName% CD%%N.mp3
  ECHO Filename:  !FileName!
  ECHO.
  ECHO Ripping CD# %%N...
  ECHO freaccmd -track all -o "!FileName!"
  ECHO CLS
  ECHO.
  ECHO.
)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Looping and adding to a counter in R

From Dev

Looping counter - shortest method

From Dev

Looping array using a counter

From Dev

looping strings without for loop or counter in C

From Dev

Access VBA - Looping with counter in variable name

From Dev

Scala: having issue with a forward reference + looping counter

From Dev

Ansible throwing error on nested looping - counter issue

From Dev

Perl - looping through Hash and changing the internal iterator counter?

From Dev

How to make dynamic looping counter when using condition

From Java

Get current batchfile directory

From Dev

Batchfile - The syntax of the command is incorrect

From Dev

making a batchfile in autoit

From Dev

Twilio Outgoing call via batchfile

From Dev

Batchfile: If file exist move it to subdirectory

From Dev

Change Filename Case DOS Batchfile

From Dev

Batchfile not working through php (timeout)

From Dev

How to mention C:\Program Files in batchfile

From Dev

How to generate string for bruteforce attack using batchfile

From Dev

change wireless networks using cmd or batchfile?

From Dev

Fix sdkmanager java.lang.NoClassDefFoundError batchfile

From Dev

python script messes up %time% in batchfile

From Dev

How can I run netsh using batchfile?

From Dev

the system cannot find the file specified in batchfile

From Dev

Batchfile - getting error access is denied using sqlcmd

From Dev

Batchfile: What's the best way to declare and use a boolean variable?

From Dev

Batchfile: Using "start" Command to Start a batch file on a specific label

From Dev

Windows 7 batchfile to iterate through subdirectories selecting first file

From Dev

Batchfile: read last lines from logfiles and copy them to a new file

From Dev

How can you create a limited loop in a batchfile program?

Related Related

  1. 1

    Looping and adding to a counter in R

  2. 2

    Looping counter - shortest method

  3. 3

    Looping array using a counter

  4. 4

    looping strings without for loop or counter in C

  5. 5

    Access VBA - Looping with counter in variable name

  6. 6

    Scala: having issue with a forward reference + looping counter

  7. 7

    Ansible throwing error on nested looping - counter issue

  8. 8

    Perl - looping through Hash and changing the internal iterator counter?

  9. 9

    How to make dynamic looping counter when using condition

  10. 10

    Get current batchfile directory

  11. 11

    Batchfile - The syntax of the command is incorrect

  12. 12

    making a batchfile in autoit

  13. 13

    Twilio Outgoing call via batchfile

  14. 14

    Batchfile: If file exist move it to subdirectory

  15. 15

    Change Filename Case DOS Batchfile

  16. 16

    Batchfile not working through php (timeout)

  17. 17

    How to mention C:\Program Files in batchfile

  18. 18

    How to generate string for bruteforce attack using batchfile

  19. 19

    change wireless networks using cmd or batchfile?

  20. 20

    Fix sdkmanager java.lang.NoClassDefFoundError batchfile

  21. 21

    python script messes up %time% in batchfile

  22. 22

    How can I run netsh using batchfile?

  23. 23

    the system cannot find the file specified in batchfile

  24. 24

    Batchfile - getting error access is denied using sqlcmd

  25. 25

    Batchfile: What's the best way to declare and use a boolean variable?

  26. 26

    Batchfile: Using "start" Command to Start a batch file on a specific label

  27. 27

    Windows 7 batchfile to iterate through subdirectories selecting first file

  28. 28

    Batchfile: read last lines from logfiles and copy them to a new file

  29. 29

    How can you create a limited loop in a batchfile program?

HotTag

Archive