Can someone make me a quick batch file that loops through file list.

Discussion in 'Scripting' started by CODYQX4, Oct 5, 2010.

  1. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,813
    45,775
    150
    #1 CODYQX4, Oct 5, 2010
    Last edited: Apr 15, 2019
    .
     
  2. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #2 MasterDisaster, Oct 5, 2010
    Last edited by a moderator: Apr 20, 2017
    The following batch will do the job
    Code:
    @echo off
    setlocal enabledelayedexpansion
    set /a n=1
    for /f "tokens=*" %%A IN ('"dir /b C:\oldfiles"') do ( call :for2 !n! "%%A"
    set /a n=!n!+1
    )
    pause
    exit
    
    :for2
    set str=%2
    set str=%str:~1,-1%
    for /f "skip=%1 tokens=*" %%a IN ('"dir /b C:\newfiles"') do echo %str% %%a & exit /b
    
    Eg. file structure
    Code:
    C:\>dir /b C:\oldfiles
    0 - Copy (2).txt
    0 - Copy (3).txt
    0 - Copy (4).txt
    0 - Copy (5).txt
    0 - Copy (6).txt
    0 - Copy (7).txt
    0 - Copy (8).txt
    0 - Copy (9).txt
    0 - Copy.txt
    0.txt
    
    C:\>dir /b C:\newfiles
    1 - Copy (10).txt
    1 - Copy (2).txt
    1 - Copy (3).txt
    1 - Copy (4).txt
    1 - Copy (5).txt
    1 - Copy (6).txt
    1 - Copy (7).txt
    1 - Copy (8).txt
    1 - Copy (9).txt
    1 - Copy.txt
    1.txt
    
    Output of above batch
    Code:
    0 - Copy (2).txt 1 - Copy (2).txt
    0 - Copy (3).txt 1 - Copy (3).txt
    0 - Copy (4).txt 1 - Copy (4).txt
    0 - Copy (5).txt 1 - Copy (5).txt
    0 - Copy (6).txt 1 - Copy (6).txt
    0 - Copy (7).txt 1 - Copy (7).txt
    0 - Copy (8).txt 1 - Copy (8).txt
    0 - Copy (9).txt 1 - Copy (9).txt
    0 - Copy.txt 1 - Copy.txt
    0.txt 1.txt
    Press any key to continue . . .
    
    1 - Copy (10).txt is an additional file in newfiles folder. It is a dummy file that needs to be on top of the list so that the second for loop runs as expected.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,813
    45,775
    150
    #3 CODYQX4, Oct 5, 2010
    Last edited: Apr 15, 2019
    (OP)
    .
     
  4. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #4 MasterDisaster, Oct 5, 2010
    Last edited by a moderator: Apr 20, 2017
    Code:
    @echo off
    setlocal enabledelayedexpansion
    set /a n=1
    for /f "tokens=*" %%A IN (oldfilelist.txt) do (
    call :for2 !n! %%A
    set /a n=!n!+1
    )
    exit
    :for2
    for /f "skip=%1 tokens=*" %%a IN (newfilelist.txt) do echo %2 %%a & exit /b
    
    Change the highlighted part to bspatch syntax.
     

    Attached Files:

    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,813
    45,775
    150
    #5 CODYQX4, Oct 5, 2010
    Last edited: Apr 15, 2019
    (OP)
    .
     
  6. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    %2 is the name of the old file
    %%a is the name of the file to be compared

    What do you want the third file name to be?
    H:\My Data\My Programs\Windows\Microsoft\Microsoft Office 2010\Crack\My Tools\Channel Switch\patched\*.patched
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,813
    45,775
    150
    #7 CODYQX4, Oct 5, 2010
    Last edited: Apr 15, 2019
    (OP)
    .
     
  8. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #8 MasterDisaster, Oct 5, 2010
    Last edited by a moderator: Apr 20, 2017
    I think this will do it
    Code:
    @echo off
    setlocal enabledelayedexpansion
    set /a n=1
    for /f "tokens=*" %%A IN (oldfilelist.txt) do (
    call :for2 !n! %%A
    set /a n=!n!+1
    )
    pause
    exit
    :for2
    for /f "skip=%1 tokens=*" %%a IN (newfilelist.txt) do (
    set str=%%a
    set str=!str:~0,-1!.patched"
    bspatch %2 %%a !str!
    exit /b
    )
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,813
    45,775
    150
    #9 CODYQX4, Oct 5, 2010
    Last edited: Apr 15, 2019
    (OP)
    .
     
  10. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,813
    45,775
    150
    #10 CODYQX4, Oct 5, 2010
    Last edited: Apr 15, 2019
    (OP)
    .
     
  11. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,813
    45,775
    150
    #11 CODYQX4, Oct 5, 2010
    Last edited: Apr 15, 2019
    (OP)
    .
     
  12. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,818
    90
    CODYQX4, did you get the volume files from wzor select?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,813
    45,775
    150
    #13 CODYQX4, Oct 5, 2010
    Last edited: Apr 15, 2019
    (OP)
    .
     
  14. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,813
    45,775
    150
    #14 CODYQX4, Oct 5, 2010
    Last edited: Apr 15, 2019
    (OP)
    .
     
  15. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    The newfilelist.txt has empty line in the beginning. There are exactly 76 lines in the oldfilelist and 77 lines in the newfilelist. If you look at the second for loop you will notice that I skip a number of lines and process only the first line and break from the loop. If you try to echo the three file names you will get exactly 76 lines of output.

    Its good that you got it working in another way. Can you post your batch file here?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,813
    45,775
    150
    #16 CODYQX4, Oct 6, 2010
    Last edited: Apr 15, 2019
    (OP)
    .