rejetto forum

Autorename of duplicate files

Caco · 28 · 14681

0 Members and 1 Guest are viewing this topic.

Offline Caco

  • Tireless poster
  • ****
    • Posts: 113
    • View Profile
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
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: 13510
    • View Profile
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
This doubles the extension of file:

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


Offline rejetto

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

Offline Caco

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