Reputation: 233
I'm trying to create a scheduled task that will run every morning to copy a file from a folder to another. So here's the problem,
The source folder's name is dynamic and starts off with the daily date (i.e. "06-Feb-13"). How can I go about creating a batch file which will be able to determine the daily date and find that folder?
Thanks in advance.
Upvotes: 1
Views: 1903
Reputation: 233
Here's the final solution I came up with for the date:
@echo off
REM -- Convert number to 3 character month--
set v=%date:~4,2%
SET map=01-Jan;02-Feb;03-Mar;04-Apr;05-May;06-Jun;07-Jul;08-Aug;09-Sep;10-Oct;11-Nov;12-Dec
CALL SET v=%%map:*%v%-=%%
SET v=%v:;=&rem.%
set y=%date:~12,4%
set d=%date:~7,2%
set "mydate=%d%-%v%-%y%"
echo %mydate%
Upvotes: 0
Reputation: 24466
If it's the newest folder you're looking for, then you can do a directory listing sorted by creation date and act on the last entry. If you know the directory you need will always be the most recently created, then there's no need to scrape and compare the actual date.
@echo off
setlocal
for /f %%I in ('dir /t:c /o:d /b "c:\path\to\containing\dir\*."') do set dir=%%I
copy "%dir%\*.*" "c:\destination\folder"
Note that I'm doing dir "path\*."
and not dir "path\*.*"
. The *.
will match directories but not files.
Upvotes: 0
Reputation:
@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
echo %mydate%_%mytime%
This Link will help you.
Upvotes: 1