How to turn a file shortcut into a copy

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Merelin
Posts: 2
Joined: 29 Dec 2011 22:23

How to turn a file shortcut into a copy

Post 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

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: How to turn a file shortcut into a copy

Post 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.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: How to turn a file shortcut into a copy

Post 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

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: How to turn a file shortcut into a copy

Post 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>);

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: How to turn a file shortcut into a copy

Post by Stefan »

serendipity wrote:Property "LinkTarget":
There is a property LinkTarget ? Great find :shock:


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 :wink:
Last edited by Stefan on 01 Feb 2012 17:19, edited 1 time in total.

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: How to turn a file shortcut into a copy

Post by serendipity »

Stefan wrote:
serendipity wrote:Property "LinkTarget":
There is a property LinkTarget ? Great find :shock:


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

Merelin
Posts: 2
Joined: 29 Dec 2011 22:23

Re: How to turn a file shortcut into a copy

Post by Merelin »

Thanks a lot! You saved my day... literally!

eil
Posts: 1875
Joined: 13 Jan 2011 19:44

Re: How to turn a file shortcut into a copy

Post 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. :cry:
Win 7 SP1 x64 100% 1366x768|1900x1080

highend
Posts: 14955
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: How to turn a file shortcut into a copy

Post 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. :cry:
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;
 }
One of my scripts helped you out? Please donate via Paypal

eil
Posts: 1875
Joined: 13 Jan 2011 19:44

Re: How to turn a file shortcut into a copy

Post 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?
To see the attached files, you need to log into the forum.
Win 7 SP1 x64 100% 1366x768|1900x1080

highend
Posts: 14955
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: How to turn a file shortcut into a copy

Post 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.
One of my scripts helped you out? Please donate via Paypal

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: How to turn a file shortcut into a copy

Post 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 :oops: ):
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.

highend
Posts: 14955
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: How to turn a file shortcut into a copy

Post 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"...
One of my scripts helped you out? Please donate via Paypal

eil
Posts: 1875
Joined: 13 Jan 2011 19:44

Re: How to turn a file shortcut into a copy

Post 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 :oops: ):
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. :oops: 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. :)
Win 7 SP1 x64 100% 1366x768|1900x1080

Post Reply