rejetto forum

Software => HFS ~ HTTP File Server => HTML & templates => Topic started by: Caco on August 31, 2009, 03:56:23 PM

Title: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: Caco on August 31, 2009, 03:56:23 PM
Quote
+ new symbols %old-name% and %new-name% for event [on macro rename]

Thank you very much for this Rejetto.  ;)

Finally i accomplished my goal by invoking an external batch script.

hfs.events:
Code: [Select]

[+on macro rename]
{.exec|cmd.exe /K rename_preview.cmd "%old-name%" "%new-name%".}


Batch script:

Code: [Select]

@echo off

set oldname=%~nx1.flv

set newname=%~nx2.flv

%~d1

cd %~p1

cd [previews]

ren "%oldname%" "%newname%"

I reported here cause it may help other users with similar needs as mine.
Title: Re: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: Mars on August 31, 2009, 05:02:55 PM
why are you rename the file by an external script when the macro rename does this job perfectly?
Title: Re: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: Caco on September 01, 2009, 11:39:24 AM
Quote
mars is right. why don't you use {.rename.} ?

Well, you know my tree structure is made so each folder has its [previews] subfolder. %old-name% and %new-name% store the entire path of the file renamed, so i needed to insert \[previews]\ between the path and the file name, eg:

%old-name% is D:\archive\video\video1.avi

but i need D:\archive\video\[previews]\  and , in that folder, video1.avi.flv.

So i think if i used macro .rename , i had to concatenate it with another macro (maybe .substring?) to get the goal.
Title: Re: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: kaler on September 01, 2009, 12:17:28 PM
What would you do with this event... i don't understand the meaning of it...
Title: Re: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: Mars on September 01, 2009, 12:39:02 PM
Quote
mars is right. why don't you use {.rename.} ?

Well, you know my tree structure is made so each folder has its [previews] subfolder. %old-name% and %new-name% store the entire path of the file renamed, so i needed to insert \[previews]\ between the path and the file name, eg:

%old-name% is D:\archive\video\video1.avi

but i need D:\archive\video\[previews]\  and , in that folder, video1.avi.flv.

So i think if i used macro .rename , i had to concatenate it with another macro (maybe .substring?) to get the goal.


you have to  use %item-folder%[preview]/%item-name%
Title: Re: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: Caco on September 01, 2009, 12:40:21 PM
Well, take for instance my case: i use HFS as a server for large video file. Anytime a new file is added, a light flash video preview is created. Without this event, it would be complex to implement autorenaming of previews (eg. you will need another software, like a folder watchdog).

Remote renaming of a file can be considered an administrative-level action, so another use of this event can be to notify in some way the admin that that kind of action has been performed,and by who.  
Title: Re: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: Caco on September 01, 2009, 12:44:33 PM
Quote
you have to  use %item-folder%[preview]/%item-name%

mmmm, i'm not sure. Once event is invoked, %item-name% already contains the new name, but i need the old name. But %old-name% contains the entire path. So i solved in that other way.  ;D
Title: Re: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: Mars on September 01, 2009, 12:52:20 PM
there are two macro  filepath and filename
usage : {.filepath|%item-url%.}   {.filename|%item-url%.}


{.filename|%old-name%.} is the solution
 ;)
Title: Re: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: Caco on September 01, 2009, 01:44:06 PM
Cannot get it to work.

Tried this without success:

{.rename|"{.filepath|%old-name%.}[previews]\{.filename|%old-name%.}.flv"|"{.filename|%new-name%.}.flv".}

Does .filepath store the drive letter also?

Title: Re: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: Mars on September 01, 2009, 03:05:05 PM
in your template

{.rename|%item-resource%|new-name.ext.}


in hfs.events

[on macro rename]
{.rename|{.filepath|%old-name%.}[previews]\{.filename|%old-name%.}|%new-name%.}

when  hfs find a macro rename, if the action rename is done, the he call the event [on macro rename] where
 %old-name% is replaced by %item-resource% and %new-name% by new-name.ext                           

the form of first param of macro rename must be a windows path as c:\........\file.ext , for the second param only the name and the ext are necessary
Title: Re: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: Caco on September 01, 2009, 04:11:36 PM
Quote
in your template

{.rename|%item-resource%|new-name.ext.}

Didn' touch anything in template. Rename function by French can can is working, so i leave it untouched.

Quote
[on macro rename]
{.rename|{.filepath|%old-name%.}[previews]\{.filename|%old-name%.}|%new-name%.}

when  hfs find a macro rename, if the action rename is done, the he call the event [on macro rename] where
 %old-name% is replaced by %item-resource% and %new-name% by new-name.ext

Uhm, but in this case the correct string would be:

{.rename|{.filepath|%item-resource%.}[previews]\{.filename|%item-resource%.}|%new-name%.}

In addition, don't forget that rename action must be done from oldname.ext.flv to newname.ext.flv  ;D


Title: Re: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: rejetto on September 04, 2009, 01:42:42 PM
if you still need a solution, then
1. tell me the content of %old-name% and %new-name%
2. tell me exactly what renaming you need to perform, with full paths

otherwise ignore this post :P
Title: Re: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: Mars on September 04, 2009, 02:04:36 PM
when he use the macro rename normaly  by {rename|my file|newname.} ,
he will to do a second action as {rename|...[previous]\%old-name%.flv|%new-name%.flv.} in the event [on macro rename]

But I have just realized, that he can use both macro in the main tpl without the help of events

.......
{rename|my file|newname.}
{rename|...[previous]\my file.flv|newname.flv.}

It is so simpler than I blame me for not having thought of it before ;)

Title: Re: new symbols %old-name% and %new-name% for event [on macro rename]
Post by: rejetto on September 04, 2009, 02:11:08 PM
it needs events because the rename is made in a script he can't or doesn't want to control