Search code examples
shellbatch-filecopybatch-processingxcopy

Batch file to copy 3 files to new directory


I have 100 Profiles that I need the cookies imported to a new folder, currently I'm using xcopy but is there a cleaner way to do it than this for the 3 files (Bookmarks, Cookies and Cookies-journal are the names)

Folders are named the same, I just need to copy the files from Profile 1 Directory 1 to Profile 1 Directory 2 - but 100 directories in order:

xcopy "C:\Users\Switch\Desktop\UserData\Profile 7\Bookmarks" "C:\Users\switch\AppData\Local\Chromium\User Data\Profile 7" /i /y

xcopy "C:\Users\Switch\Desktop\UserData\Profile 7\Cookies" "C:\Users\switch\AppData\Local\Chromium\User Data\Profile 7" /i /y

xcopy "C:\Users\Switch\Desktop\UserData\Profile 7\Cookies-journal" "C:\Users\switch\AppData\Local\Chromium\User Data\Profile 7" /i /y


Solution

  • Next time please give some kind of attempt, but, either way, a nested for loop should do the trick.

    @echo off
    for /l %%G in (0,1,99) do (
        for %%H in (Bookmarks Cookies Cookies-journal) do (
            xcopy "C:\Users\Switch\Desktop\UserData\Profile %%~G\%%~H" "C:\Users\switch\AppData\Local\Chromium\User Data\Profile %%~G" /i /y
        )
    )
    

    The first for loop, for /l %%G goes from 0-->99,

    The second indented one for %%H goes through each of the file names mentioned,

    Then put the current profile number %%~G, and the current file %%~H into the xcopy command as they belong.


    Note, the for /l %%G loop starts with a Profile 0, if this isn't desired, just use (firstNumber,amountToAddEachLoop,lastNumber) for example (1,1,100) to go from 1-->100