1

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.

trigun0x2
  • 233
  • 3
  • 13

3 Answers3

1
@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.

Community
  • 1
  • 1
  • 2
    To add to this answer, see the "Map and Lookup" section on this [DOS String Manipulation](http://www.dostips.com/DtTipsStringManipulation.php) page to see how to convert the 2-digit month to its alpha abbreviation. – rojo Feb 07 '13 at 13:14
  • @rojo Thanks for the followup help! – trigun0x2 Feb 07 '13 at 13:25
  • 2
    You can vote up comments as well as answers to increase its value –  Feb 07 '13 at 13:30
0

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.

rojo
  • 24,000
  • 5
  • 55
  • 101
  • It's not the newest folder. All the folders are created at the same time but just named to the date. – trigun0x2 Feb 07 '13 at 12:56
  • @JeffreyTong - in that case, [what have you tried](http://mattgemmell.com/2008/12/08/what-have-you-tried)? – rojo Feb 07 '13 at 13:01
  • I was searching for a something to display the current date so I can truncate it to the proper format and use that as the directory name. – trigun0x2 Feb 07 '13 at 13:07
0

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%
trigun0x2
  • 233
  • 3
  • 13