Search code examples
batch-filedos

Destination Folder Batch file


I currently use a .bat file

I'm able to copy a test.cfg file in a folder named testVersion434 using copy test.cfg testVersion434.

Unfortunately I am unable to copy the file test.cfg to a folder that begins with testXXXXXXXX

I'll have in the future Folders testVersion43x that will create , and I would copy test.cfg in all folders who begin with test

I can list all of them with dir test*


Solution

  • You will need to enumerate the target folders and execute a copy operation for each one

    for /d %%a in ("c:\folders\test*") do copy "c:\file\test.cfg" "%%~fa"
    

    The for /d command will iterate over the indicated set of folders and, for each one, the code after the do clause is executed, with %%a holding a reference to the folder being iterated. %%~fa is the full path of the folder.