Problem creating links (lnk files) - One too many created!

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Wheathead
Posts: 45
Joined: 18 Sep 2021 13:31

Problem creating links (lnk files) - One too many created!

Post by Wheathead »

I wrote a short script to test making file links from selected files in the XYplorer list.

I used the "new" command for link and I used report to get the selection without folders (I'm fat fingered, so I sometimes select a folder with my selection and I don't want to make any folder links. My test was selecting 3 files. When I execute the script from the Catalog, it creates an additional link file which included the .txt extension and added .lnk extension.
See image.
https://1drv.ms/u/s!Ah7Ct43sFaoEgq5brof ... Q?e=toMs7s
Image

Here is the script:

Code: Select all

"Create Shortcuts of Selected Files"

  $selFiles = Report("{Dir |{Fullname}|}<crlf>", 1);
  $itemcount = Get("CountSelected",$selFiles);
 
  msg $selFiles "Number of Items Selected" $itemcount;

  foreach($file, $selFiles, "<crlf>"){
 
  //new(name, [type=file|dir|link|symlink|hardlink|junction], [source], [flags])  

  new(getpathcomponent($file,"base"),"link",$file);
  }
I'm not sure why, could use advice here.
Thanks
Monitor 1 Current Resolution 1280x720 pixels Scaling 150%
Monitor Width 1920 Monitor Height 1080
Monitor 2 S34CG50 on NVIDIA Quadro T1000 Scaling 175%
Monitor Width 3440 Monitor Height 1440

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

Re: Problem creating links (lnk files) - One too many created!

Post by highend »

Your report creates a trailing <crlf> and you happily loop over that empty item^^

So e.g. trim it or use a loop type, that skips empty entries foreach ($file, $selFiles, <crlf>, "e") {
One of my scripts helped you out? Please donate via Paypal

Wheathead
Posts: 45
Joined: 18 Sep 2021 13:31

Re: Problem creating links (lnk files) - One too many created!

Post by Wheathead »

Thanks highend, that was perfect! Using "e"

Code: Select all

"Create Shortcuts of Selected Files"

  $selFiles = Report("{Dir |{Fullname}|}<crlf>", 1);
  $itemcount = Get("CountSelected",$selFiles);
 
  foreach($file, $selFiles, "<crlf>", "e"){
 
  //new(name, [type=file|dir|link|symlink|hardlink|junction], [source], [flags])  

  new(getpathcomponent($file,"base"),"link",$file);
  }
  // msg $selFiles "Number of Items Selected" $itemcount;
Monitor 1 Current Resolution 1280x720 pixels Scaling 150%
Monitor Width 1920 Monitor Height 1080
Monitor 2 S34CG50 on NVIDIA Quadro T1000 Scaling 175%
Monitor Width 3440 Monitor Height 1440

Post Reply