Link to home
Create AccountLog in
Avatar of charmedimsure
charmedimsure

asked on

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
Avatar of Glenn_Moore
Glenn_Moore

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

ASKER

So what should the syntax be then?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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
*Hi Fives* @ SteveGTR... You hit it right on the nail. Thanks!