Reputation: 109
I have a abc.txt
file. I would like to create a batch file to copy abc.txt
file with today date as file name. The file name like 20150821good.txt
How can I change the following code:
copy *.txt 20150821good.txt
Upvotes: 2
Views: 86
Reputation: 24466
You can use the first 8 characters of wmic os get localdatetime
to get today's date. Capture it with for /f
. Example:
@echo off
setlocal
for /f %%I in ('wmic os get localdatetime /value ^| find "="') do set "%%I"
set "today=%localdatetime:~0,8%"
if not exist "combined\" md combined
rem // remove "echo" when you're confident this does what you intend
echo copy *.txt "combined\%today%good.txt"
Upvotes: 1