Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.


Batch File does not work

  • Please log in to reply
1 reply to this topic

#1 prm123


  • Members
  • 2 posts
  • Local time:07:39 AM

Posted 22 September 2014 - 12:07 AM

I have created a batch file to pick MP3 files recursively from a given folder and copy them into three folders B0 (first 999 files), B1 (next 999 files) and B3 balance files of total of about 2800 files. Also write file number & its path to three corresponding text files: MP3_0.txt for the first 999 files. MP3_1.txt for next 999 files and MP3_2.txt for the balance files. The batch file commands given are as below:


@echo off
SetLocal EnableDelayedExpansion
set /A x=0
set dest=
For /F "delims=," %%f in (MP3_CDs_12GB_List.txt) DO (
    set /A x+=1 
    if !x! leq 999    goto B0
    if !x! leq 1999  goto B1
    if !x! leq 2800  goto B2
goto continue
        copy "%%f" "e:\Fls_MP3\B0\"
        echo !x! %%f >> "e:\Fls_MP3\MP3_0.txt
        goto continue
        copy "%%f" "e:\Fls_MP3\B1\"
        echo !x! %%f >> "e:\Fls_MP3\MP3_1.txt
        goto continue
        copy "%%f" "e:\Fls_MP3\B2\"
        echo !x! %%f >> "e:\Fls_MP3\MP3_2.txt
        goto continue
echo atContinue
echo "Next file"
echo "Finished"
goto :eof
When run it just writes the first MP3 file and stops the batch program.
Any help to correct the prgram and make it usable will be appreciated
------ PRAKASH   prm123

Edited by hamluis, 22 September 2014 - 09:26 AM.
Moved from Win 7 to Programming - Hamluis.

BC AdBot (Login to Remove)



#2 x64


  • Members
  • 352 posts
  • Gender:Male
  • Location:London UK
  • Local time:02:09 AM

Posted 22 September 2014 - 02:42 PM

I do not think that batch file control structures are sophisticated enough to have goto statements nested in the for loop. When you use goto, it forgets that it is in the for loop.


Maybe use the if statements to set another variable (which would be the number of the set to add the file to).




SetLocal EnableDelayedExpansion
set /A x=0

For /F "delims=," %%f in (list.txt) DO (
    set /A x+=1
    echo !x! %%f
    if !x! leq 15 set /A y=3
    if !x! leq 10 set /A y=2
    if !x! leq 5 set /A y=1
echo Chose !y!

echo "Finished"
goto :eof

Then integrate y into your paths and output...


Something like that....



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users