Search code examples
windowscommand-lineloopsbatch-filexcopy

Batch (xcopy all files to folder) with loop


can anyone help me with loop in batch for windows? i want make script that will allow me to do something like this:

1. copy all folders and files from Drive I: to X:\folder0001;
2. when done display: "Done"; (i ejected cd)
3. "enter" to next copy;

1. copy all folders and files from Drive I: to X:\folder0002;
2. when done display: "Done"; (i ejected cd)
3. "enter" to next copy;

...

1. copy all folders and files from Drive I: to X:\folder0010;
2. when done display: "Done"; (i ejected cd)
3. "enter" to next copy;


button q = exit

copy i do with changing manually number with command:

for %%f in (i:) do xcopy %%f X:\folder001\ /e,

i want only press enter and change cd

but i dont know how to create this script :(


Solution

  • Try the following:

    @echo off
    setlocal enabledelayedexpansion
    set number=1
    FOR /L %%C IN (1,1,100) DO (
      set dest=!number!
      for %%N in (9999 999 99 9) do if !number! LEQ %%N set dest=0!dest!
      xcopy I\*.*I:\folder!dest!" /E /I
      ECHO *** CHANGE CD OR CTRL-C TO QUIT****
      PAUSE
      set /a number+=1
    )
    

    I don't think there's a way to check input from the keyboard.