alothe
(Lurker)
2005-06-28 02:42 PM
Renaming files using KIX

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?


Jose
(Seasoned Scripter)
2005-06-28 03:11 PM
Re: Renaming files using KIX

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



LonkeroAdministrator
(KiX Master Guru)
2005-06-28 03:23 PM
Re: Renaming files using KIX

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.


Jose
(Seasoned Scripter)
2005-06-28 03:24 PM
Re: Renaming files using KIX

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



Jose
(Seasoned Scripter)
2005-06-28 03:25 PM
Re: Renaming files using KIX

Good one DOC, maybe I did the hard one.

LonkeroAdministrator
(KiX Master Guru)
2005-06-28 03:29 PM
Re: Renaming files using KIX

doc?

what is "jooel UDF"?

dude... have you passed over, again?


alothe
(Lurker)
2005-06-28 03:46 PM
Re: Renaming files using KIX

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...


JochenAdministrator
(KiX Supporter)
2005-06-28 04:01 PM
Re: Renaming files using KIX

@time contains several ":" which are afaik illegal in filenames

Jose
(Seasoned Scripter)
2005-06-28 04:20 PM
Re: Renaming files using KIX

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.


LonkeroAdministrator
(KiX Master Guru)
2005-06-28 06:25 PM
Re: Renaming files using KIX

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.


Jose
(Seasoned Scripter)
2005-06-28 09:16 PM
Re: Renaming files using KIX

Its nice to be punished by a mod every now and then I kinda missed that feeling.

Jose
(Seasoned Scripter)
2005-06-28 09:34 PM
Re: Renaming files using KIX

To be honest Jooel Nieminen.....the avatar confused me thinking that you where DOC.

Am I getting old?


AllenAdministrator
(KiX Supporter)
2005-06-28 10:59 PM
Re: Renaming files using KIX

Jooel... is this what you didn't write? or are you talking about some other UDF?

Jose
(Seasoned Scripter)
2005-06-28 11:12 PM
Re: Renaming files using KIX

lol true Allen!!
I will have to edit the above post again....I shoudnt pay that much of attention to some basta.


LonkeroAdministrator
(KiX Master Guru)
2005-06-29 12:15 AM
Re: Renaming files using KIX

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.