Page 1 of 1
How to turn a file shortcut into a copy
Posted: 29 Dec 2011 22:36
by Merelin
Hi there!
Is there a way to turn a file shortcut into a copy of the related file?
I just set up a little music library specially for dj sets but on half the way i decided to use real copys instead of file shortcuts so i can also edit the tracks without destroying the original file in my main music library.
I tried the search function but didnt get anything related to my problem.
Thanks
Melvin
Re: How to turn a file shortcut into a copy
Posted: 30 Dec 2011 09:54
by Marco
No. There could be a way via scripting, if that fits your needs (although I don't have much time at the moment).
At first I thought about hardlinks, but since you say you would use the copies for safety and preservation-of-the-original purposes consider the option ruled out.
Re: How to turn a file shortcut into a copy
Posted: 30 Dec 2011 10:22
by Stefan
Hi Melvin, welcome.
Merelin wrote:Is there a way to turn a file shortcut into a copy of the related file?
Only step-by-step per file:
Right-click a LNK file, then use submenu Shortcut Target and there "Copy Shortcut Target Item"
Unfortunately i can't find an command ID for this command to use this with an script.
And an try to use readfile() to get the target link from the LNK fails because readfile() stops at first found 0
Re: How to turn a file shortcut into a copy
Posted: 30 Dec 2011 16:57
by serendipity
Stefan wrote:Hi Melvin, welcome.
Merelin wrote:Is there a way to turn a file shortcut into a copy of the related file?
Only step-by-step per file:
Right-click a LNK file, then use submenu Shortcut Target and there "Copy Shortcut Target Item"
Unfortunately i can't find an command ID for this command to use this with an script.
And an try to use readfile() to get the target link from the LNK fails because readfile() stops at first found 0
Property "LinkTarget":
text property("LinkTarget", <curitem>);
Re: How to turn a file shortcut into a copy
Posted: 30 Dec 2011 18:46
by Stefan
serendipity wrote:Property "LinkTarget":
There is a property LinkTarget ? Great find
Then it is possible indeed:
copyto "<curpath>", property("LinkTarget", <curitem>);
Script to walk through all files in current folder and copy the target
from all found *.lnk files to the current folder, if it not already exists:
Code: Select all
////Start at top:
sel 1;
while(1){
////Loop through all items:
if ("<curitem>"==""){break;}
////If current file has *.LNK extension:
if ( recase("<curext>", "lower") == "lnk" ){
////If target file not already exists in current folder:
$TargetFile = gettoken(property("LinkTarget", <curitem>), -1, "\");
if (exists( "<curpath>\$TargetFile") != 1 ){
////copy target file to current folder:
copyto "<curpath>", property("LinkTarget", <curitem>);
}
////Delete *.lnk file:
//delete [recycle=1], [confirm], [itemlist]
//delete 1, 1, "<curitem>";
}
sel "+1";
}
Thanks serendipity!
EDIT: more proper indention

Re: How to turn a file shortcut into a copy
Posted: 30 Dec 2011 19:13
by serendipity
Stefan wrote:serendipity wrote:Property "LinkTarget":
There is a property LinkTarget ? Great find
Then it is possible indeed:
copyto "<curpath>", property("LinkTarget", <curitem>);
Script to walk through all files in current folder and copy the target
from all found *.lnk files to the current folder, if it not already exists:
Code: Select all
////Start at top:
sel 1;
while(1){
////Loop through all items:
if ("<curitem>"==""){break;}
////If current file has *.LNK extension:
if ( recase("<curext>", "lower") == "lnk" ){
////If target file not already exists in current folder:
$TargetFile = gettoken(property("LinkTarget", <curitem>), -1, "\");
if (exists( "<curpath>\$TargetFile") != 1 ){
////copy target file to current folder:
copyto "<curpath>", property("LinkTarget", <curitem>);
}
////Delete *.lnk file:
//delete [recycle=1], [confirm], [itemlist]
//delete 1, 1, "<curitem>";
}
sel "+1";
}
Thanks serendipity!
Don't mention Stefan. You help a lot around here, so its not a big deal. I just happened to have an old script to see all file properties which I often use but never shared. Anyway, I just posted it here.
http://www.xyplorer.com/xyfc/viewtopic. ... 261#p67261
Re: How to turn a file shortcut into a copy
Posted: 30 Dec 2011 21:19
by Merelin
Thanks a lot! You saved my day... literally!
Re: How to turn a file shortcut into a copy
Posted: 01 Feb 2012 10:31
by eil
to not make a different topic, can someone please modify this script so that it doesn't copy targeted files, but show a list of all real pathes via "text"?
i thought that at least this i'll be able to do, but seems i'm still too bad at xy scripting.

Re: How to turn a file shortcut into a copy
Posted: 01 Feb 2012 11:40
by highend
eil wrote:to not make a different topic, can someone please modify this script so that it doesn't copy targeted files, but show a list of all real pathes via "text"?
i thought that at least this i'll be able to do, but seems i'm still too bad at xy scripting.

You mean something like this?
Code: Select all
sel 1;
$LinkList = "";
while(1){
////Loop through all items:
if ("<curitem>"==""){break;}
////If current file has *.LNK extension:
if ( recase("<curext>", "lower") == "lnk" ){
////If target file not already exists in current folder:
$TargetFile = property("LinkTarget", <curitem>);
if (exists( "<curpath>\$TargetFile") != 1 ){
////copy target file to current folder:
// copyto "<curpath>", property("LinkTarget", <curitem>);
$LinkList = $LinkList . $TargetFile . <crlf>;
}
////Delete *.lnk file:
//delete [recycle=1], [confirm], [itemlist]
//delete 1, 1, "<curitem>";
}
sel "+1";
}
if($LinkList != "") {
text $LinkList;
}
Re: How to turn a file shortcut into a copy
Posted: 01 Feb 2012 16:54
by eil
can't say 'cause i don't see the result of script's work, but this:
script.png
what am i doing wrong?
Re: How to turn a file shortcut into a copy
Posted: 01 Feb 2012 17:05
by highend
Regarding the modifications to the original script:
Remove the if condition on the last lines. But: When $LinkList is empty, there is nothing to display....
Ofc I've tested it before and it works without errors (at least here).
Regarding your script:
Öh, if(""==""){break;}... The if condition will always be true, so your break; will always terminate the loop.
Re: How to turn a file shortcut into a copy
Posted: 01 Feb 2012 17:16
by Stefan
eil wrote:can't say 'cause i don't see the result of script's work, but this:
script.png
what am i doing wrong?
Please be sure to have all lines indented at least by one blank at the start of the line.
If you copy the above script that is not given and you get the result you mentioned.
See
Common questions, mistakes and pitfalls - Indent your code!
For those who post scripts (me included

):
please be sure to have at least
two blanks in front of each line, because the forum eats always one.
I usually use even three or four.
Re: How to turn a file shortcut into a copy
Posted: 01 Feb 2012 17:23
by highend
please be sure to have at least two blanks in front of each line, because the forum eats always one
It was just a fast copy of the posted script, edit and post back ;(
Wouldn't it be better to change the forum's code then? It's not the users "fault"...
Re: How to turn a file shortcut into a copy
Posted: 01 Feb 2012 19:20
by eil
highend wrote:Regarding your script:
Öh, if(""==""){break;}... The if condition will always be true, so your break; will always terminate the loop.
it wasn't my script, it was wrong copied yours modification.
Stefan wrote:Please be sure to have all lines indented at least by one blank at the start of the line.
If you copy the above script that is not given and you get the result you mentioned.
See
Common questions, mistakes and pitfalls - Indent your code!
For those who post scripts (me included

):
please be sure to have at least
two blanks in front of each line, because the forum eats always one.
I usually use even three or four.
shame on me.

i still didn't find a time to read through whole guide/tips topics. yet, i really just copied it and didn't expect for it to not work, as i understand it was tested before posting - too bad forum brings such nuisance.
now all works. thanks
highend and
Stefan.
