Solved .bat to copy and paste with user input

January 7, 2014 at 10:01:40
Specs: Windows 7
Hello. I am learning alot about .bat files and I was asked by a coworker about a batch file that could copy from 1 location and paste to another. This issue is that this would be done daily and the target file will change by date. Is there a way to run a batch file and us user input to target the file with the date as part of the file name?

See More: .bat to copy and paste with user input

Report •

January 7, 2014 at 11:47:11
✔ Best Answer
You need to account for the date layout.

But you might be money ahead by just copying the latest file.

::====== script starts here ===============
:: family.bat 2014-01-08 2:37:46.75
@echo off & setLocal enableDELAYedeXpansioN

pushd c:\temp

for /f "tokens=* delims= " %%a in ('dir/b/a-d/o-d *.jpg') do (
set src=%%a
goto :done
copy "%src%" D:\files > nul
::====== script ends here =================

M2 Golden-Triangle

Report •

January 7, 2014 at 12:02:37
So a little more info on the topic. There are about 50 files that would need to be copied from a server location to a 2nd "local" server. I guess what I am thinking is something that will take user input YYYYMMDD and put that into the file name for the 50 files that would be copied.

eg. copy z:\file_a_YYYYMMDD.xls x:\
copy z:\file_b_YYYYMMDD.xls x:\


Report •

January 7, 2014 at 13:49:05
There's probably more to this than I'm accounting for, but just to break the ice:
::====== begin batchscript - prompted
@echo off & setlocal
set dt=
set /p dt=YYYYMMDD:
if defined dt for %%a in (z:\*_%dt%.xls) do copy %%a x:\
::===== end batchscript

If you prefer commandline argument to suppply input:
if "%1" neq "" for %%a in (z:\*_%1.xls) do copy %%a x:\

Report •
Related Solutions

Ask Question