Batch file to copy single file to multiple places

First of all I am very new to writing batch files. What I want to do is create a .bat that will copy a file to several locations(all within the same folder, however with different names).

I have a folder that contains the master copy of my db and I want to run the batch file to update the users db files. The reason being is they each use thier own front end.

The research I've done has me thinking I can do this with a for loop going through my users folder and then copy over each file, but I can't seem to put it together.

Any help would be great.

2 answers Last reply
More about batch file copy single file multiple places
  1. Hi Abs,

    If the user names are typically unchanged, I would do this:

    xcopy master.db user1.db /v /c /h /r /k /o /y
    xcopy master.db user2.db /v /c /h /r /k /o /y
    xcopy master.db user3.db /v /c /h /r /k /o /y

    This assumes that you place and run the batch file from within the folder that you are copying in. If you use other folders or place the batch file elsewhere, the filenames have to be preceeded by the correct path

  2. This is what I've come up with but its not working.

    dir /b *.accdb> filelist.txt
    FOR /F "tokens=1" %%G IN (filelist.txt) DO copy /Master/database.accdb %%G

    It loops through my folder that has all my user dbs, and creates the filelist text file. Then I loop through each db name in the filelist text file and save it as %%G. If I echo %%G it comes up with the name of the each file properly, however when I use it in the copy command it won't save the file. I'm wondering if it's because %%G isn't a string, or if I need a pause to give it time to save. Either way that is where I am stuck.

    I see you used xcopy, perhaps I need to acquaint myself with it.

    Thanks for you post, and that looks like it would work, however I want to automate this a little more, incase we add more users.
Ask a new question

Read More

Windows XP