[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1321
  • Last Modified:

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
0
charmedimsure
Asked:
charmedimsure
1 Solution
 
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
 
SteveGTRCommented:
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
 
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

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Tackle projects and never again get stuck behind a technical roadblock.
Join Now