copy script to search for source file

I'm trying to copy a Windows backup file (VHD) to a Samba share that is backed up off site weekly.  However- I need to only backup the VHD (not the XML files, directories, etc.) and place the VHD in the root of the share.  I can of course do this manually, but would like to instead schedule a script to run weekly.

The hard part is getting my script to search the WindowsImageBackup\...\ directories for the VHD files before copying.  Is there a copy tool, such as xcopy, that will search subdirectories for the source file, or does anyone have a handy dandy script?
Who is Participating?
Bill PrewConnect With a Mentor Commented:
Here's a small BAT script that should do the job, it uses the DIR command to find all VHD files under the base folder you specify, including subfolders, and then processes that list copying each file to the destination backup location.

Save as a BAT file and adjust the SET lines near the top as needed.

@echo off

set BaseDir=C:\WindowsImageBackup
set DestDir=Z:\Backup

for /f "tokens=*" %%A in ('dir /b /s /a-d "%BaseDir%\*.vhd"') do (
  copy "%%~A" "%DestDir%"

Open in new window

Santosh GuptaConnect With a Mentor Commented:
Try this

forfiles /p  "D:\" /s /m *.vhd  /c "cmd /c copy @file E:\backup"
AllenAuthor Commented:
Thanks for the response.  

I received- ERROR: Invalid argument/option - '@file'

D:\ is the source & E:\backup is the destination, correct?
Santosh GuptaCommented:
Note: do not use '\' after source and destination name. like C:\temp NOT C:\temp\

yes, D:\ is the source & E:\backup is the destination.
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.