Batch Files

  • Thread starter Thread starter Mike Ford
  • Start date Start date
M

Mike Ford

Create a batch file with the following, substituting
whatever you want to do for the copy command (adapted from
a file by Michael Jerkovic)

@ECHO off
SETLOCAL


FOR /f "tokens=2-4 skip=1 delims=(-)" %%G IN
('echo.^|date') DO (
FOR /f "tokens=2 delims= " %%A IN ('date /t') DO (
SET v_first=%%G
SET v_second=%%H
SET v_third=%%I
SET v_all=%%A
)
)

SET %v_first%=%v_all:~0,2%
SET %v_second%=%v_all:~3,2%
SET %v_third%=%v_all:~6,4%

copy C:\whatever.txt c:\%mm%.%dd%.%yy%.txt

ENDLOCAL & SET v_year=%yy%& SET v_month=%mm%& SET
v_day=%dd%
 
Hi Mike,

I saved that file as a .bat file...set my txt file to be copied but it
doesn't work unfortunately :(

Thanks,

Chris.
 
Ah, I see. The line breaks don't work when copied from
the post. Send me an email and I will send you the file.

Mike

Either that or take the @echo off command out and run it.
The output should look like this (you will need to remove
line breaks to get it to look like this when copied from
the previous post):

C:\>date.bat

C:\>SETLOCAL

C:\>FOR /F "tokens=2-4 skip=1 delims=(-)" %G IN
('echo.|date') DO (FOR /F "token
s=2 delims= " %A IN ('date /t') DO (
SET v_first=%G
SET v_second=%H
SET v_third=%I
SET v_all=%A
) )

C:\>(FOR /F "tokens=2 delims= " %A IN ('date /t') DO (
SET v_first=mm
SET v_second=dd
SET v_third=yy
SET v_all=%A
) )

C:\>(
SET v_first=mm
SET v_second=dd
SET v_third=yy
SET v_all=08/15/2003
)

C:\>SET mm=08

C:\>SET dd=15

C:\>SET yy=2003

C:\>copy C:\whatever.txt c:\08.15.2003.txt
1 file(s) copied.

C:\>ENDLOCAL & SET v_year=2003 & SET v_month=08 & SET
v_day=15
 
Back
Top