Copy a file to a folder using wildcards at MS-DOS Prompt

Posted on 2007-09-28
Last Modified: 2012-08-14
I have a Word doc named z123.doc  I need to copy it to a several similar folder paths

The similar folder paths are G:\Specialty Services(\in here is there userid i.e. jdoe this part changes)\Word

I tried copy C:\z123.doc G:\Specialty Services\*\Word\  in MS Dos but it did not work

What syntax do I need to use to get this to work?

Question by:charmedimsure
    LVL 14

    Expert Comment

    The first section of the copy is the to location, the second part is the from location.

    Author Comment

    So what should the syntax be then?

    LVL 30

    Accepted Solution

    You could create a batch file and do it like so:

    @echo off


    set fileName=C:\z123.doc
    set destRoot=G:\Specialty Services

    for /f "tokens=*" %%a in ('dir /b /ad "%destRoot%" 2^>NUL') do if exist "%destRoot%\%%a\Word" copy "%fileName%" "%destRoot%\%%a\Word"
    LVL 9

    Expert Comment

    you can try this:
    @echo off
    for /F %%a in ('dir /b /ad c:\temp') do copy C:\z123.doc G:\SpecialtyServices\%%a\Word

    or vbscript:
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    srcDir = "G:\SpecialtyServices"
    srcFile = "C:\z123.doc"
    Set objFolder = objFSO.GetFolder(srcDir)
    For Each folder In objFolder.SubFolders
          objFSO.CopyFile srcFile , folder.Path&"\"&"z123.doc"
    Set objFolder=Nothing
    Set objFSO=Nothing

    save as myscript.vbs and on command prompt, type: cscript /nologo myscript.vbs

    Expert Comment

    *Hi Fives* @ SteveGTR... You hit it right on the nail. Thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
    No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
    The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
    Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now