Author Topic: Autorename of duplicate files  (Read 7361 times)

0 Members and 1 Guest are viewing this topic.

Offline Caco

  • Tireless poster
  • ****
  • Posts: 113
    • View Profile
Autorename of duplicate files
« 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.

Offline Caco

  • Tireless poster
  • ****
  • Posts: 113
    • View Profile
Re: Autorename of duplicate files
« Reply #1 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?

Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12949
    • View Profile
Re: Autorename of duplicate files
« Reply #2 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.

Offline Caco

  • Tireless poster
  • ****
  • Posts: 113
    • View Profile
Re: Autorename of duplicate files
« Reply #3 on: May 26, 2009, 04:32:51 PM »
This doubles the extension of file:

name.ext----->name (1).ext------->name.ext.ext  ;)

Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12949
    • View Profile
Re: Autorename of duplicate files
« Reply #4 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"

Offline Caco

  • Tireless poster
  • ****
  • Posts: 113
    • View Profile
Re: Autorename of duplicate files
« Reply #5 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 :)

Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12949
    • View Profile
Re: Autorename of duplicate files
« Reply #6 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

Offline Caco

  • Tireless poster
  • ****
  • Posts: 113
    • View Profile
Re: Autorename of duplicate files
« Reply #7 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




Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12949
    • View Profile
Re: Autorename of duplicate files
« Reply #8 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" ?

Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12949
    • View Profile
Re: Autorename of duplicate files
« Reply #9 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

Offline Caco

  • Tireless poster
  • ****
  • Posts: 113
    • View Profile
Re: Autorename of duplicate files
« Reply #10 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...

Offline Caco

  • Tireless poster
  • ****
  • Posts: 113
    • View Profile
Re: Autorename of duplicate files
« Reply #11 on: May 27, 2009, 08:50:43 AM »
Is there a [on file deletion] event?

Offline Caco

  • Tireless poster
  • ****
  • Posts: 113
    • View Profile
Re: Autorename of duplicate files
« Reply #12 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.

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1880
    • View Profile
Re: Autorename of duplicate files
« Reply #13 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

 ;)

Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12949
    • View Profile
Re: Autorename of duplicate files
« Reply #14 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?