rejetto forum

new symbols %old-name% and %new-name% for event [on macro rename]

Caco · 14 · 5326

0 Members and 1 Guest are viewing this topic.

Offline Caco

  • Tireless poster
  • ****
    • Posts: 113
    • View Profile
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.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
why are you rename the file by an external script when the macro rename does this job perfectly?


Offline Caco

  • Tireless poster
  • ****
    • Posts: 113
    • View Profile
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.


Offline kaler

  • Occasional poster
  • *
    • Posts: 94
    • View Profile
What would you do with this event... i don't understand the meaning of it...


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
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%


Offline Caco

  • Tireless poster
  • ****
    • Posts: 113
    • View Profile
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.  


Offline Caco

  • Tireless poster
  • ****
    • Posts: 113
    • View Profile
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


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
there are two macro  filepath and filename
usage : {.filepath|%item-url%.}   {.filename|%item-url%.}


{.filename|%old-name%.} is the solution
 ;)
« Last Edit: September 01, 2009, 12:55:01 PM by Mars »


Offline Caco

  • Tireless poster
  • ****
    • Posts: 113
    • View Profile
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?



Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
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


Offline Caco

  • Tireless poster
  • ****
    • Posts: 113
    • View Profile
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




Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
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


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
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 ;)



Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
it needs events because the rename is made in a script he can't or doesn't want to control