It is currently Tue May 07, 2024 11:30 PM


All times are UTC - 7 hours [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Fri Jul 01, 2005 10:46 AM 

I am writting a batch file to zip up some sql .bak files and move them to a different drive. Problem is, this needs to run every day. Anyone know of a command line option to rename a file with the days date so that I won't keep getting the "Are you sure you want to overwrite the file named ".." ?<
>
<
>
<i></i>


Top
  
 
PostPosted: Fri Jul 01, 2005 10:57 AM 

@ECHO off
SETLOCAL
IF [%1] NEQ [] goto s_start

:: Tested for Windows NT, 2K, XP

ECHO STAMPME.cmd
ECHO REName a file with the DATE/Time
ECHO.
ECHO SYNTAX
ECHO STAMPME TestFile.txt
ECHO.
ECHO STAMPME "Test File.txt"
ECHO.
ECHO STAMPME "c: docsTest File.txt"
ECHO.
ECHO Will rename the file in the format "Test mailto:File-02-12-27@16-55.txt"
ECHO.
ECHO In a batch file use CALL STAMPME ...

:: To change the filename format just change around the last line below

GOTO :eof

:s_start

SET v_file=%~n1%
SET v_pathname=%~f1%
SET v_ext=%~x1%

::Get the date
:: note ISO 8601 date format would require 4 digit YYYY Year)

FOR /f "tokens=6-8 delims=/ " %%G IN ('NET TIME \%computername%') DO (
SET v_mm=%%G
SET v_dd=%%H
SET v_yy=%%I
)

:: Get the time
FOR /f "tokens=1,2 delims=: " %%G IN ('time/t') DO (
SET v_hr=%%G
SET v_min=%%H
)

ECHO Today is Year: [%v_yy%] Month: [%v_mm%] Day: [%v_dd%]
ECHO The time is: [%v_hr%]:[%v_min%]

REN "%v_pathname%" "%v_file%-%v_yy%-%v_mm%-%v_dd%@%v_hr%-%v_min% Prophion<
>
Dwarf Hunter of Kargath<
>
<Cult of the Moonkin><
>
300 Skill Dragonscale Leatherworker<i>Edited by: Vanamar  at: 7/1/05 1:08 pm<
></i>


Top
  
 
PostPosted: Fri Jul 01, 2005 10:58 AM 

and uh, that's a .cmd, not a .bat, so it'll only work on WinNT based systems. Prophion<
>
Dwarf Hunter of Kargath<
>
<Cult of the Moonkin><
>
300 Skill Dragonscale Leatherworker<i></i>


Top
  
 
PostPosted: Fri Jul 01, 2005 11:28 AM 

ok, so I can't get it to work. <
>
<
>
It is running on an Win2k server the file name is daily.zip and it's path is E sqlbackdaily.zip<
>
<
>
post what you would have changed to mirror that file loc.<
>
<i></i>


Top
  
 
PostPosted: Fri Jul 01, 2005 11:53 AM 

You'd change nothing. You'd name that file stamp.cmd, and you'd type "stamp.cmd e:sqlbackdaily.zip" Prophion<
>
Dwarf Hunter of Kargath<
>
<Cult of the Moonkin><
>
300 Skill Dragonscale Leatherworker<i></i>


Top
  
 
PostPosted: Fri Jul 01, 2005 11:55 AM 

One caveat... it doesn't seem to be keeping the file extension, and I'm not sure why, heh. Prophion<
>
Dwarf Hunter of Kargath<
>
<Cult of the Moonkin><
>
300 Skill Dragonscale Leatherworker<i></i>


Top
  
 
PostPosted: Fri Jul 01, 2005 11:59 AM 

file extension doesnt matter. I'll know what the file is. Gonna try it.
b.<
>
<
>
It works, but isn't consistant. It doesn't always put the date in just ---@ but it does always have the time. <
>
<
>
I'll mess with it some. Thanks<
>
<i>Edited by: Xkhanx at: 7/1/05 2:38 pm<
></i>


Top
  
 
PostPosted: Fri Jul 01, 2005 8:11 PM 

It's been a long time since I've touched command-line syntax, but I think I remember two ways to disable that verification step. Some old DOS commands had an undocumented switch, /Y, that would bypass confirmation messages. You also used to be able to put "VERIFY OFF" on a line early in the file, and that would turn off confirmations. Tranthas Stormwalker<
>
<i></i>


Top
  
 
PostPosted: Fri Jul 01, 2005 8:45 PM 

Yeah, using xcopy with a /y switch it automatically assumes yes. But I don't want the files over written, i wan't hourly backups of the files.<
>
<
>
What Vanamar found works good even without the .zip extension.<
>
<
>
Thanks van. <i></i>


Top
  
 
PostPosted: Sat Jul 02, 2005 5:12 AM 

Awesome. Glad it worked out. Tranthas Stormwalker<
>
<i></i>


Top
  
 
PostPosted: Sun Jul 03, 2005 8:01 AM 

Hrmm... Would this fix the file extension problem?<
>
<
>
Change the line:<
>
<
>
REN "%v_pathname%" "%v_file%-%v_yy%-%v_mm%-%v_dd%@%v_hr%-%v_min%<
>
<
>
To<
>
<
>
REN "%v_pathname%" "%v_file%-%v_yy%-%v_mm%-%v_dd%@%v_hr%-%v_min%.v_ext<
>
<
>
-Deladar <i></i>


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 7 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Theme created StylerBB.net
Karma functions powered by Karma MOD © 2007, 2009 m157y