rejetto forum

Software => HFS ~ HTTP File Server => Beta => Topic started by: Caco on May 26, 2009, 02:28:36 PM

Title: Autorename of duplicate files
Post by: Caco on May 26, 2009, 02:28:36 PM
Hi rejetto, it's me once again  ;D

In HFS there's a function that autorenames duplicate files according to this schema:

file.ext

file (1).ext

file (2).ext

and so on. Unfortunately, my system cannot accept file names with spaces in the name, and this function adds one. Can you tell me how can i modify HFS to overcome this problem? "_(1)" instad of " (1)" would be perfect for me. Thank you in advance.
Title: Re: Autorename of duplicate files
Post by: Caco on May 26, 2009, 02:47:45 PM
Sorry, i posted in the wrong place.

Anyways, i think:

[upload completed]
{.replace| (1)|_(1)|%item-name%.}

cannot work,cause what if the duplicate is above 1?
Title: Re: Autorename of duplicate files
Post by: rejetto on May 26, 2009, 04:17:40 PM
untested

[+upload completed]
{.rename|%item-resource%|{.filepath|%item-resource%.}{.replace| |_|{.filename|%item-resource%.}.}.}


you can solve the problem also with event [upload name], but it's harder to script.
Title: Re: Autorename of duplicate files
Post by: Caco on May 26, 2009, 04:32:51 PM
This doubles the extension of file:

name.ext----->name (1).ext------->name.ext.ext  ;)
Title: Re: Autorename of duplicate files
Post by: rejetto on May 26, 2009, 04:53:06 PM
what HFS version are you using?
i tested. uploaded "Miranda IM (1).zip" and became "Miranda_IM_(1).zip"
Title: Re: Autorename of duplicate files
Post by: Caco on May 26, 2009, 04:54:06 PM
I'm sorry, I did a mistake, your script works perfectly, thank you very much, one of these days i'll make a donation for sure :)
Title: Re: Autorename of duplicate files
Post by: rejetto on May 26, 2009, 05:01:25 PM
this solution does not work very well.
because it renames " (1)" to "_(1)".
next time, HFS will give again " (1)" because there's no file with such name.
and again, the script will try to rename it to "_(1)", but this one already exists.
the result is: the second time the file is not renamed.

you can
1. keep it as it is, if you like
2. delete the "_(1)" file before the rename
3. script the [upload name] event, that's totally different
Title: Re: Autorename of duplicate files
Post by: Caco on May 26, 2009, 05:10:44 PM
Well to be honest i have a little problem.

You know each file i upload is being mencoded and a .flv copy placed in a subfolder called [previews]

Modifying your script accordingly doesn't work:

{.rename|%folder-resource%\[previews]\%item-name%.flv|{.filepath|%folder-resource%\[previews]\%item-name%.flv.}{.replace| |_|{.filename|%folder-resource%\[previews]\%item-name%.flv.}.}.}

Probably a syntax problem, i'll work on it tomorrow  :P



Title: Re: Autorename of duplicate files
Post by: rejetto on May 26, 2009, 05:10:46 PM
what's in your system that doesn't support space in file names?
did you try surrounding with "double quotes" ?
Title: Re: Autorename of duplicate files
Post by: rejetto on May 26, 2009, 05:14:27 PM
to know what's wrong you must enabl menu > debug > macros.log
so you can see what's happening to the script

posting the whole script instead of just the last command may help.

anyway, i can suggest to use a var like
{.set|fn|%folder-resource%\[previews]\%item-name%.flv.}
so you can then work on it
{.rename|{.^fn.}| etc etc etc
Title: Re: Autorename of duplicate files
Post by: Caco on May 27, 2009, 08:20:49 AM
I've looked into the thread you opened about events, but i didn't find a detailed list, so i don't know how [upload name] works...
Title: Re: Autorename of duplicate files
Post by: Caco on May 27, 2009, 08:50:43 AM
Is there a [on file deletion] event?
Title: Re: Autorename of duplicate files
Post by: Caco on May 27, 2009, 11:08:43 AM
Rejetto please help me!  :P

I tried this:

{.set|itemnospace|{.substring| |(|%item-name%.}.}
{.save|itemnospace.txt|var=itemnospace.}

to transform "file (1).txt" in "file(1).txt" but it didn't work.
Title: Re: Autorename of duplicate files
Post by: Mars on May 27, 2009, 11:28:36 AM
{.rename|%item-resource%|{.filepath|%item-resource%.}{.replace| (|(|{.filename|%item-resource%.}.}.}

will replace all  ' (' by '('   then file (1).txt replaced by file(1).txt

 ;)
Title: Re: Autorename of duplicate files
Post by: rejetto on May 27, 2009, 11:38:51 AM
mmm, i think that it would be better if you don't need to specify the filepath in {.rename.}
i would change it so that, if no slash is found, then it assumes the same folder.
do you agree?
Title: Re: Autorename of duplicate files
Post by: Caco on May 27, 2009, 11:44:10 AM
Guys, i think all this doesn't resolve my issue, cause even if i shorten the filename file(1).txt, next time HFS will look up for file (1).txt  :D
Title: Re: Autorename of duplicate files
Post by: Mars on May 27, 2009, 11:55:01 AM
TO rejetto:

son problème est là où l'espace est en trop
Quote
 while fileExists(data.uploadDest) do
    begin
    inc(i);
    data.uploadDest:=format('%s\%s (%d)%s', [f.resource, fn, i, ext]);
    end;

à toi de définir si on doit retirer l'espace ou alors le remplacer par un  '_'
Quote
 while fileExists(data.uploadDest) do
    begin
    inc(i);
    data.uploadDest:=format('%s\%s_(%d)%s', [f.resource, fn, i, ext]);
    end;
Title: Re: Autorename of duplicate files
Post by: Caco on May 27, 2009, 11:57:33 AM
I roughly understand what you wrote, but if you write in english is better  ;D
Title: Re: Autorename of duplicate files
Post by: SilentPliz on May 27, 2009, 12:28:49 PM
Guys, i think all this doesn't resolve my issue, cause even if i shorten the filename file(1).txt, next time HFS will look up for file (1).txt  :D

   
No, you misunderstood.
The solution given by mars, simply removes the space in the file name:

' (' By '('

eg:
file (1).txt > file(1).txt

file (2).txt > file(2).txt

So this solution must work.

****************************************
The post in french is for rejetto... it concerns the programming of hfs.
Title: Re: Autorename of duplicate files
Post by: Caco on May 27, 2009, 12:54:29 PM
No , i didn't misunderstood. It's just like rejetto explained before:

Quote
this solution does not work very well.
because it renames " (1)" to "_(1)".
next time, HFS will give again " (1)" because there's no file with such name.
and again, the script will try to rename it to "_(1)", but this one already exists.
the result is: the second time the file is not renamed.

So the result is

file.ext

file(1).ext

file (1).ext

file (2).ext

and so on.

I hate spaces!  >:(
Title: Re: Autorename of duplicate files
Post by: Caco on May 27, 2009, 01:51:39 PM
Where i can find the complete list of all hfs events?  :'( (maybe with description)
Title: Re: Autorename of duplicate files
Post by: rejetto on May 27, 2009, 02:45:42 PM
i will write a better script asap, in the while you should answer these questions :P

what's in your system that doesn't support space in file names?
did you try surrounding with "double quotes" ?



Where i can find the complete list of all hfs events?  :'( (maybe with description)

menu > help > full guide
http://www.rejetto.com/wiki/index.php/HFS:_Event_scripts
Title: Re: Autorename of duplicate files
Post by: Caco on May 27, 2009, 03:53:51 PM
Well, actually my hfs.events is:

[+upload completed]
{.exec|cmd.exe /K mencoder %item-resource% -o %folder-resource%\[previews]\%item-name%.flv -of lavf -oac mp3lame -lameopts abr:br=56 -srate 22050 -ovc lavc -lavcopts vcodec=flv:vbitrate=256:mbd=2:trell:last_pred=1.}

And works. Well, to be honest i cannot cut the /K parameter and tons of cmd remains open, but... ;D

Quoting and spaces make this no longer work.

In addition, i already told my mates to save their file with underscore, if i revert they will kill me  ;D
Title: Re: Autorename of duplicate files
Post by: Caco on May 27, 2009, 04:05:49 PM
Can you add [on file deletion]?

I explain you why.

You know i store previews in [previews] subfolder , i integrate the modifications made by French Can Can to add "delete" options to RAWR template. Now i had to intruct HFS not only to delete file on request, but also the related preview  ;)

I know i'm asking you much, and i would like to donate, but i can't do it via Internet. Is there any other way to do it? (al limite ti faccio un bonifico o un vaglia :P)
Title: Re: Autorename of duplicate files
Post by: rejetto on May 27, 2009, 04:42:16 PM
Quoting and spaces make this no longer work.

i think you misunderstood.
use "%item-resource%" instead of %item-resource%.
on command line, file with spaces must be quoted.

ok, i will add an event for deletion.

se clicki donate ottieni già le informazioni per il bonifico :)
comunque non ti preoccupare, una donazione fa sempre piacere, ma non è certo per soldi che do l'assistenza, altrimenti non ti basterebbero €100 :D
Title: Re: Autorename of duplicate files
Post by: Caco on May 27, 2009, 05:16:30 PM
Quote
use "%item-resource%" instead of %item-resource%.

No i understood but... OMFG i never imagined that it could work, indeed it works!!!  ;D

I would expect "mencoder error: could not find file %item-resource%". Shit! I must remember to always do ALL tests! Now it will be hard to tell my mates "ehm...remember i told you to put underscores instead of spaces? Now put back spaces instead of underscores"  :-[ ;D

Quote
ok, i will add an event for deletion.

Thank you VERY much ^_____^

Quote
se clicki donate ottieni già le informazioni per il bonifico

Ah! Non avevo mai cliccato perchè pensavo fosse solo PayPal!

No, tranquillo non sto cercando di "comprarti" l'asistenza, voglio farti una donazione perchè mi piace il tuo software e perchè sei disponibile nell'assistenza  ;D ;)
Title: Re: Autorename of duplicate files
Post by: rejetto on May 27, 2009, 05:31:07 PM
you can use a tool to rename all underscores with spaces in the files you already got.
it takes seconds.
Title: Re: Autorename of duplicate files
Post by: Caco on May 28, 2009, 09:44:47 AM
Yes , i know. Computers don't complain, people often do.  ;D