7 replies
by nichorton
By: Nick
==============================
copy and paste
==============================
@echo off
rem Determine which pass we are making
if "%1"=="" goto _1stpass
if "%2"=="" goto _wdpass
if "%3"=="" goto _daypass
if "%4"=="" goto _mmpass
rem Extract the year
find "/20%4" tmp$$$.$$$ > nul
if not errorlevel==1 if errorlevel==0 set yearnr_=%4
find "/20%4" tmp$$$.$$$ > nul
if not errorlevel==1 if errorlevel==0 set yearnr_=%4
goto _end
rem Extract the month
:_mmpass
find "%3/" tmp$$$.$$$ > nul
if not errorlevel==1 if errorlevel==0 set monthnr_=%3
goto _end
rem Extract the day
:_daypass
find "/%2/" tmp$$$.$$$ > nul
if not errorlevel==1 if errorlevel==0 set daynr_=%2
goto _end
rem As an extra demo also get the name ofthe weekday
:_wdpass
find "%1" tmp$$$.$$$ > nul
if not errorlevel==1 if errorlevel==0 set weekday_=%1
goto _end
rem Put the date in a file so that find can be applied on it
:_1stpass
echo.|date > tmp$$$.$$$
rem Go through all the alternatives. Note the dummy x parameters
rem to determine which part of the date is being processed
for %%d in (Sun Mon Tue Wed Thu Fri Sat) do call %0 %%d
for %%d in (01 02 03 04 05 06 07 08 09 10) do call %0 x %%d
for %%d in (11 12 13 14 15 16 17 18 19 20) do call %0 x %%d
for %%d in (21 22 23 24 25 26 27 28 29 30 31) do call %0 x %%d
for %%d in (01 02 03 04 05 06 07 08 09 10 11 12) do call %0 x x %%d
for %%d in (97 98 99 00 01 02) do call %0 x x x %%d
rem Show the results
echo %weekday_%
echo%yearnr_%%monthnr_%%daynr_%
rem change this part
copy "c:\old\old.mdb" "d:\new\new_%weekday_%_%monthnr_%%daynr_%%yearnr_%.mdb"
rem Clean up
set weekday_=
set daynr_=
set monthnr_=
set yearnr_=
del tmp$$$.$$$
:_end
by shanghai sam
by dklippert
You could use the VBA statement "Name".
OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName ' Move and rename file.
While the "Name" statement can't contain wild cards, the variable can contain concatenate elements. Oldfile & Now
by shanghai sam
by beermonster
Hi,
I'm assuming you know the filename before hand, if not you can easily code around it. For an NT4 and above system the main line you want is
for /F "tokens=2" %%A in ('date /t') do set myvar=%%A
This sets myvar to the current date. Ifyou want to cut out any back or forward slashes (depending on your locale) then add
set myvar=%myvar:/=%
set myvar=%myvar:\=%
now you can rename as -
ren myfile.txt newname%myvar%.txt
Hope this helps...
by shanghai sam
by lanman phil
This discussion is closed to new replies.
Trending Windows Forum posts
Sort by Trending