Page 1 of 1 1
Topic Options
#142523 - 2005-06-28 02:42 PM Renaming files using KIX
alothe Offline
Lurker

Registered: 2005-06-28
Posts: 2
Loc: Oslo, Norway
Hi...

Is there anyway I can use KIX to rename a file from for example LOG to LOG-[DATE]-[TIME]?

For example by using @Date and @Time?

Top
#142524 - 2005-06-28 03:11 PM Re: Renaming files using KIX
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Hi alothe:
Should be something like this.
Code:
  
Dim $date, $path, $file, $new
$path='c:\temp'
$file=$path+'\LOG.txt'
$date="@YEAR-@MonthNo-@MDayNo"
$new="Log-"+$date+".txt"
If Exist ($file)
Shell "%ComSpec% /c rename "+$file+" "+$new+""
? @SERROR
EndIf
Get $t

_________________________
Life is fine.

Top
#142525 - 2005-06-28 03:23 PM Re: Renaming files using KIX
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22303
Loc: OK
good code snippet but please don't use it.

just do simply:
Code:
move "c:\someWild\myfile.ext" "c:\someWild\myfile_"+@year+@monthno+@mdayno+".ext"



in english, jose... we do have move, you know?
thus, no need for shelling.
_________________________
!

download KiXnet

Top
#142526 - 2005-06-28 03:24 PM Re: Renaming files using KIX
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
BTW...In order to work ok with file formats ( '/' or ':' not allowed FE) you can try Jooel UDF too..
Code:
  
$date=Replace("@DATE","/","-")
$time=Replace("@TIME",":","-")

? $date
? $time

Function Replace($String,$SS,$RS)
$Replace=Join(Split($String,$SS),$RS)
EndFunction
Get $t



Edited by Jose (2005-06-28 11:12 PM)
_________________________
Life is fine.

Top
#142527 - 2005-06-28 03:25 PM Re: Renaming files using KIX
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Good one DOC, maybe I did the hard one.
_________________________
Life is fine.

Top
#142528 - 2005-06-28 03:29 PM Re: Renaming files using KIX
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22303
Loc: OK
doc?

what is "jooel UDF"?

dude... have you passed over, again?
_________________________
!

download KiXnet

Top
#142529 - 2005-06-28 03:46 PM Re: Renaming files using KIX
alothe Offline
Lurker

Registered: 2005-06-28
Posts: 2
Loc: Oslo, Norway
Thanks for your help.

Im pretty new to Kix... so I have some problems fuguring out the different syntaxes. I like to think Im getting a hang of it.

I tried both your methods, and the both worked perfectly.

I then tried jamming a @TIME macro after your "@YEAR-@MonthNo-@MDayNo", so it reads "@YEAR-@MonthNo-@MDayNo-@TIME", but this creates the error message:

"A duplicate file name exists, or the file cannot be found."

I verified that the file Im trying to rename is in the dir, and that there is no file with the NEW name, but still the error occurs...

Any ideas?

I think I'll steer clear of the UDF for now... I like to understand whats going on before it gets to advanced... baby-steps, you know? :-)

and, thanks for bearing with me...

Top
#142530 - 2005-06-28 04:01 PM Re: Renaming files using KIX
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6345
Loc: Stuttgart, Germany
@time contains several ":" which are afaik illegal in filenames
_________________________



Top
#142531 - 2005-06-28 04:20 PM Re: Renaming files using KIX
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Aha alothe....taking Joch tip you can take a look above at Replace() function, there I replace ':' illegal with '-' of @time.

BTW....Lonkero I thought Replace() was yours. Pardon pardon.
_________________________
Life is fine.

Top
#142532 - 2005-06-28 06:25 PM Re: Renaming files using KIX
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22303
Loc: OK
and still, jose, I'm not DOC.

and, no... replace function should not be used with any kix version above 4.10 which introduced join()

now you can replace anything with simple join-split:
Code:
join(split(@time,":"),"") ? ;replaces all the occurances of ":" in @time with ""



like you see, it's a simple task, replacing that is and thus I never wrote UDF for that.
there is no use.
_________________________
!

download KiXnet

Top
#142533 - 2005-06-28 09:16 PM Re: Renaming files using KIX
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Its nice to be punished by a mod every now and then I kinda missed that feeling.
_________________________
Life is fine.

Top
#142534 - 2005-06-28 09:34 PM Re: Renaming files using KIX
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
To be honest Jooel Nieminen.....the avatar confused me thinking that you where DOC.

Am I getting old?
_________________________
Life is fine.

Top
#142535 - 2005-06-28 10:59 PM Re: Renaming files using KIX
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4396
Loc: USA
Jooel... is this what you didn't write? or are you talking about some other UDF?
Top
#142536 - 2005-06-28 11:12 PM Re: Renaming files using KIX
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
lol true Allen!!
I will have to edit the above post again....I shoudnt pay that much of attention to some basta.
_________________________
Life is fine.

Top
#142537 - 2005-06-29 12:15 AM Re: Renaming files using KIX
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22303
Loc: OK
ja!
allen, I was not sure did I do it or not, so I decided to say I didn't.
indeed, I wrote that udf to show that the other one was really an overkill.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


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

Who's Online
1 registered (KevinOfOz) and 155 anonymous users online.
Newest Members
phanhuyen345, msmile032, bellamabel2018, lmnopq098068, nathanjame
17561 Registered Users

Generated in 0.037 seconds in which 0.012 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