Delete target of shortcut

Discuss and share scripts and script files...
Post Reply
xynoob
Posts: 2
Joined: 06 Feb 2016 00:21

Delete target of shortcut

Post by xynoob »

I want to be able to select a bunch of shortcut files (.lnk) and delete both the shortcut and the target file. So I tried the following:

Code: Select all

foreach($filename, "<get SelectedItemsPathNames |>") {
  $target = property("#ShortcutTarget", $filename);
  delete $target;
  delete $filename
}
The variable values all seem OK i.e. when it gets to "delete $target", it shows the actual target filename. But when I get confirmation for delete, it is for the shortcut only, not the target. What am I doing wrong... this seems it should be straightforward.

TIA

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Delete target of shortcut

Post by bdeshi »

Hold on. The delete command in XYplorer has three parameters in a strict order.
::rtfm 'idh_scripting_comref.htm#idh_sc_delete'; wrote:

Code: Select all

delete [recycle=1], [confirm], [itemlist]
You've actually completely skipped the first two params, therefore the command has no valid itemlist, and defaults to deleting the currently focused/selected file(s).

Use this script instead.

Code: Select all

 foreach($filename, "<get SelectedItemsPathNames |>") {
  $target = property("#ShortcutTarget", $filename);
  delete 1, 1, $target; //all parameters must exist...
  delete  ,  , $filename; //...but they can be left empty
 }
Or this one if you want less prompts.

Code: Select all

 step;
 foreach($filename, "<get SelectedItemsPathNames |>") {
  $target = property("#ShortcutTarget", $filename);
  if confirm("Delete these items?|$target|$filename",'|') {
   delete 1, 0, $target;
   delete 1, 0, $filename;
  }
 }
And: Welcome to the club! :D
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

xynoob
Posts: 2
Joined: 06 Feb 2016 00:21

Re: Delete target of shortcut

Post by xynoob »

Doh! Thanks - works great after adding the mandatory parameters!

Post Reply