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

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?

Thanks
charmedimsureAsked:
Who is Participating?
 
SteveGTRConnect With a Mentor Commented:
You could create a batch file and do it like so:

@echo off

setlocal

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"
0
 
Glenn_MooreCommented:
The first section of the copy is the to location, the second part is the from location.
0
 
charmedimsureAuthor Commented:
So what should the syntax be then?

Thanks
0
 
ghostdog74Commented:
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"
Next
Set objFolder=Nothing
Set objFSO=Nothing

save as myscript.vbs and on command prompt, type: cscript /nologo myscript.vbs
0
 
lubin_5200Commented:
*Hi Fives* @ SteveGTR... You hit it right on the nail. Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.