Page 1 of 1 1
Topic Options
#14346 - 2001-11-15 05:15 PM renaming files using variables
mikew50 Offline
Fresh Scripter

Registered: 2001-11-15
Posts: 17
Loc: NJ
I am new kix script user. What I am trying to do is copy and rename files using variables. They are log files but I want the new name to be the date it was created. Any help would be appreciated.
mike

here is a sample of what i have already:

$file="j:\drs1\drs1backup\*.log"
$newname="j:\drs1\drs1backup\@Date.log"
if exist $file
shell '%comspec% /c ren $oldfile $newfile'

Top
#14347 - 2001-11-15 08:15 PM Re: renaming files using variables
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Mike,

You will probably need to parse out the relevant Date information..

code:

BREAK ON CLS

?@Date

; -- Assuming @Date yields, 2001/11/15

$Mo = SUBSTR(@date, 6, 2)
$Day = SUBSTR(@date, 9, 2)
$Year = SUBSTR(@date, 1, 4)
$Date = "$Mo$Day$Year"

?$Date



Once you get this, change the following line to be -

$newname="j:\drs1\drs1backup\$Date.log"

HTH,

- Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#14348 - 2001-11-15 10:08 PM Re: renaming files using variables
mikew50 Offline
Fresh Scripter

Registered: 2001-11-15
Posts: 17
Loc: NJ
Kent
Thanks I'll give it a shot!
Mike

Top
#14349 - 2001-11-16 02:11 AM Re: renaming files using variables
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Welcome to the board.

We are using in our version the GetFileTime function to get
the date of last modification of a file.
The change all "*.LOG" files to the format "YYYYMMDD.LOG". No renaming
when file is in use or new file already exist.


Our version:

code:

$log_directory="j:\drs1\drs1backup"
;
$tmp_file="%temp%\zzzzz.tmp"
SHELL '%comspec% /c dir "$log_directory\*.log" /b >$tmp_file '
IF (Open(1,$tmp_file,2) = 0)
$old_file=ReadLine(1)
WHILE (@error = 0)
? $old_file+" -> "+GetFileTime($old_file)
$fdate=GetFileTime($old_file)
IF (len($fdate) <> 0)
$new_file= substr($fdate,1,4)+substr($fdate,6,2)+substr($fdate,9,2)
; $new_file=$new_file+"_"+substr($fdate,12,2)+substr($fdate,15,2)+substr($fdate,18,2)
$new_file=$new_file+".log"
;
IF ($old_file <> $new_file) AND (Exist($log_directory+"\"+$new_file) = 0)
? 'rename "$log_directory\$old_file" "$new_file" '
shell '%comspec% /c ren "$log_directory\$old_file" "$new_file" '
ELSE
? '-skip- "$log_directory\$old_file" (duplicate entry)'
ENDIF
ELSE
? '-skip- "$log_directory\$old_file" '
ENDIF
$old_file=ReadLine(1)
LOOP
IF Close(1)
ENDIF
ENDIF
DEL $tmp_file


It is also possible to change it to "YYYYMMDD_HHMMSS.LOG" format. You only need
to remove ; symbol in line 12.
greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 640 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.052 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org