Computer Hope

Microsoft => Microsoft DOS => Topic started by: Osoful on August 20, 2012, 08:55:35 PM

Title: Xcopy with dynamic file name as parameter
Post by: Osoful on August 20, 2012, 08:55:35 PM
I need to copy a file from one directory to another directory using xcopy. The file that I need to copy is always named differently based on the date it was created.
My questions are: 
a)how can I construct the file name dynamically, e.g. 2012-08-08-tfile.txt
and 
b) can I pass this file name to xcopy 

Thanks for your help.
Title: Re: Xcopy with dynamic file name as parameter
Post by: foxidrive on August 20, 2012, 09:12:31 PM
Does the file always have tfile in the name?

Is the file the only .txt file in the folder?

Title: Re: Xcopy with dynamic file name as parameter
Post by: Osoful on August 20, 2012, 10:02:07 PM
yes, it's always tfile at the end. it's currently not the only file in the directory but I could set it up that way if it makes it easier.
Title: Re: Xcopy with dynamic file name as parameter
Post by: foxidrive on August 21, 2012, 03:20:34 AM
Then this should work from the same folder.

Code: [Select]
@echo off
for %%a in (*tfile.txt) do xcopy "%%a" "d:\target\"