如何指定lnk文件的目标_用于复制或移动所选文件以及快捷方式目标文件(由.lnk引用)的集合的脚本

如何指定lnk文件的目标

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk)

用于复制或移动鼠标选择的文件集合以及快捷方式(.lnk)引用的目标的脚本

The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scripting methods for handling copying/moving of file system objects, ...overcoming the limitation for interfacing with the Windows Clipboard imposed on scripts and the command processor interface (command line).

本文的目的是帮助阐明使用简单的脚本方法来处理文件系统对象的复制/移动的实际挑战和可用选项(可能存在的地方),从而克服与Windows剪贴板接口所施加的限制脚本和命令处理器界面(命令行)。

===============================

========================= =====

How would you like to be able to create a script that allows you to simply

您希望如何创建一个脚本,使您能够简单地

 arbitrarily select some files within a Window (directory)

在窗口(目录)中任意选择一些文件

 including shortcuts

包括捷径

 and copy or move all the targets, i.e., the real files in the directory, and the real files the shortcuts point to (but not the shortcuts themselves)

并复制或移动所有目标,即目录中的实际文件,以及快捷方式指向的实际文件(而不是快捷方式本身)

 ...to another directory location?

...到另一个目录位置?

Heretofore, the only way via simple scripting I have seen to do this is to create a list from a selection and use that to make a batch you then use for copying or moving the files.  (pita)

迄今为止,我所看到的通过简单脚本编写脚本的唯一方法是根据选择内容创建一个列表,并使用该列表创建一个批处理,然后将其用于复制或移动文件。 (皮塔)

The only other way I can think of to otherwise facilitate this is by creating an application, or DLL Wrapper, or shell extension, for interfacing to the system clipboard (which I really want to do for my 2nd dll project)... however, all I want to do right now is use a "SIMPLE" script...

我能想到的另一种方式来促进此操作的唯一方法是创建一个应用程序或DLL Wrapper或Shell扩展,以与系统剪贴板接口(我确实想为我的第二个dll项目做这件事)...但是,我现在要做的就是使用“简单”脚本...

-- what to do??

- 该怎么办??

***Well, I finally figured out a way to do this with a very simple script, although it still must rely on a small outside helper.

***好吧,尽管它仍然必须依靠一个小的外部帮助程序,但我终于找到了一种使用非常简单的脚本来完成此操作的方法。

===========================

========================= =

THE CHALLENGE:

挑战:

There seem to be essentially three problems to tackle here...

这里似乎要解决三个问题...

#1 - the script must be able to 'receive' a collection of filesystem objects that is passed to it, and

#1-脚本必须能够“接收”传递给它的文件系统对象的集合,并且

#2 - parse them correctly, i.e., collect the files passed, and collect the targets of the shortcut targets that are passed, and

#2-正确解析它们,即收集传递的文件,并收集传递的快捷方式目标的目标,以及

#3  - the script must be able to then pass that collection of filesystem object 'pointers' to the clipboard, or something, for temporary storage until we are ready to paste the files elsewhere.

#3-脚本必须能够将文件系统对象“指针”的集合传递给剪贴板或用于临时存储的东西,直到我们准备将文件粘贴到其他位置为止。

===========================

========================= =

THE OBSTACLES:

障碍:

If you do any vbs/wsh/bat scripting you have probably run into the following limitations imposed by Microsoft:

如果执行任何vbs / wsh / bat脚本,则可能会遇到Microsoft施加的以下限制:

1) You cannot directly access the clipboard from a script.  I have looked high and low and have not found a single script-centric workaround for this limitation.

1)您不能直接从脚本访问剪贴板。 我一直都在寻找并没有找到针对此限制的单个以脚本为中心的解决方法。

 - So you cannot, say, pass/copy a file selection (control-click/control-select one or several files for a collection) onto your script to be held in the system clipboard for pasting to a destination you later navigate to.  (Trust me... ain't gonna happend without a DLL wrapper or some other utility).

-因此,您不能说通过/复制文件选择(control-click / control-sel 将一个或几个文件集合)保存到系统剪贴板中的脚本中,以粘贴到稍后导航到的目标位置。 (相信我……没有DLL包装器或其他实用程序就不会发生)。

  - As well, I would not accept having to resort to AutoIt or a third-party clipboard manager or anything like those that you have to continually have running in the background.  Sloppy, unnecessary, and unacceptable.

-同样,我不接受诉诸AutoIt或第三方剪贴板管理器或类似的东西,而这些东西必须不断在后台运行。 马虎,不必要和不可接受。

2)You cannot pass several 'arguments' (images) from the shell (e.c., control-click/control-select several files for an images collection) to a "command-line-prepared" script without either parameters/arguments being lost, or the scripts launching multiple instances of themselves (an instance for each image/argument passed).

2)您不能从外壳传递几个“参数”(图像)(例如,control-click / control-sele 将多个图像文件集保存到一个“命令行准备好的”脚本中,而不会丢失任何参数/参数,或者脚本会启动自身的多个实例(每个传递的图像/参数的实例)。

 Example: Say you setup a context menu in the registry with your script reference looking something like -->>

示例:假设您在注册表中设置了上下文菜单,脚本引用看起来像->>

wscript C:\myscript.vbs "%*"   ::<<--or do something similarly for a batch::

wscript C:\ myscript.vbs“%*” :: <<-或类似地对批处理:

...That type of argument usage (%* in a command line) doesn't exist for scripts, and using, say for instance, "%1" only results in the mulitple instances issue mentioned.  There is no way I found to successfully pass an argument list of arbitrarily selected objects to a command-line-prepared script... again, ain't gonna happen with Batch or VBS. (Well, maybe using a listbox, but obviously  that's too combersome.)

...这种类型的参数用法(脚本中的%*)在脚本中不存在,例如使用“%1”仅会导致提到多个实例问题。 我发现没有办法成功地将任意选择的对象的参数列表传递给命令行准备的脚本……同样,Batch或VBS也不会发生这种情况。 (嗯,也许使用列表框,但是显然太麻烦了。)

3) Scripts do not support DDE linking (for setting up and passing a collection).  (**However, there may be a command line dde utility you can find out there that can be implemented for the solution being discussed here, ...I have not looked too deeply into that, but it seems viable ;^)

3)脚本不支持DDE链接 (用于设置和传递集合)。 (**但是,可能有一个命令行dde实用程序,您可以在那里找到该实用程序,可以针对此处讨论的解决方案实施该程序,...我并没有对此进行深入研究,但似乎可行; ^)

4) I have not yet ventured into PowerShell, but to mention... it may be possible to open multiple images with one instance using PS, either directly or with DDE manipulation or with batch integration.  It may even be possible to utilize the clipboard (like if you can recapture spinoffs of cmdlet extensions Get-Clipboard Out-Clipboard, but I do not know about their object handling capabilities).  

4)我还没有冒险使用PowerShell,但是要说……有可能直接或通过DDE操作或通过批处理集成使用PS使用一个实例打开多个图像。 甚至有可能利用剪贴板(例如,是否可以重新捕获cmdlet扩展的衍生产品Get-Clipboard Out-Clipboard,但我不知道它们的对象处理能力)。

  I have seen some discussions on this, but no SIMPLE VIABLE solution to speak of has presented itself as yet (not that they aren't out there, I just didn't find any within the time allotted for searching on this subject, so I am staying focussed on Batch and/or VBS solution).

我已经看到了一些讨论,但是还没有一个简单可行的解决方案可以提出来(不是说它们还不存在,我只是没有在分配的时间内找到任何关于此主题的内容,所以我我将重点放在批处理和/或VBS解决方案上)。

***5) You cannot drop a collection of arbitrarily selected files (images) onto a BATCH without causing the script to launch an instance of itself for every file passed (by arbitrarily, again, I mean this assumes you do not have a preconception for the number of files that will be selected - which you 'can' script for).

*** 5)您不能将任意选择的文件(图像)的集合拖放到BATCH上,而不会导致脚本为传递的每个文件启动其自身的实例(再次,这是任意地,我假设您没有先入为主的观念) (表示可以选择的文件数)。

!!!...but you CAN do this with a vbs script!

!!! ... 但是您可以使用vbs脚本执行此操作

okay....

好的....

===========================

========================= =

***WHAT WORKS THEN***

***然后起作用***

PART 1 of 2: A script that can receive and parse arguments.

第1部分,共2部分:一个可以接收和解析参数的脚本。

After much searching, and almost giving up, I finally figured out that I may be able to leaverage that last caveat (in #5 above) to my advantage, assuming, of course, that I could write a script to then handle parsing and passed arguments (images or fileObjects) in the way I desire.

经过大量的搜索,几乎放弃了,我终于想出我可以为自己的利益做出最后的警告(在上面的#5中),当然,假设我可以编写一个脚本来处理解析并通过参数(图像或fileObjects)以我想要的方式。

THERE ARE TWO WAYS TO DO THIS

有两种方法可以做到这一点

1) Create a vbs script (unfortunately a batch will not work) and set it up someplace where you can always drag+drop your selection of files onto it.  

1)创建一个vbs脚本(不幸的是,该批处理将不起作用)并将其设置在某个位置,您可以随时在其中拖放文件选择。

Of course, this is easily accomplished with the Startbar's handy-dandy "Quick Launch" Toolbar.

当然,使用Startbar方便的“快速启动”工具栏可以轻松完成此操作。

OR

要么

2) ***You can place a shortcut to your vbscript in Window's "SendTo" context menu !

2) ***您可以在Window的“ SendTo”上下文菜单中放置vbscript的快捷方式!

To quickly access your SendTo folder simply launch Run (Win-R) and type in shell:sendto  ..and hit enter.

要快速访问您的SendTo文件夹,只需启动运行(Win-R)并键入shell:sendto ..,然后按Enter。

----------------------

----------------------

Okay, so now that I know the options for acceptable script file 'type' and 'placement', and 'how to use it' so it can successfully receive a collection that I want to hand off to it...,

好的,现在我知道了可接受的脚本文件“类型”和“放置”以及“如何使用”的选项,这样它就可以成功接收我想交给它的收藏了……,

...well all I need to do now is figure out what goes inside it ;^)

...现在我要做的就是找出其中的内容; ^)

But scripts cannot directly utilize the Windows Clipboard, so now what?

但是脚本不能直接利用Windows剪贴板,那么现在该怎么办?

===========================

========================= =

***WHAT WORKS THEN***

***然后起作用***

PART 2 of 2: A way to handle the clipboard, or store system object pointers to use for pasting files elsewhere later.

第2部分,共2部分:处理剪贴板或存储系统对象指针的方法,以便以后在其他位置粘贴文件。

Hmmmm... wait a minute, Houston, we have a serious problem.  There's no way in hell to hand off a "shell objects pointers" collection to the clipboard from a script 8^?  {A shell objects "pointer" is what is passed to the clipboard when typically copying files and folders (not the objects themselves ;^}

嗯...等等,休斯顿,我们遇到了严重的问题。 在地狱中没有办法从脚本8 ^将“外壳对象指针”集合传递到剪贴板。 {Shell对象的“指针”是通常复制文件和文件夹(不是对象本身; ^}时传递到剪贴板的内容。

You can hand off text collections, or even file contents using a script... but there is no way a script can directly utilize the system clipboard for file system objects, like you do using the 'copy' command  with Ctrl-C or in the context menu when you right-click a file (or group of them).

您可以使用脚本来传递文本集合甚至文件内容...但是脚本无法像使用Ctrl-C或在Ctrl-C中使用'copy'命令那样直接使用系统剪贴板来处理文件系统对象右键单击一个文件(或其中的一个组)时的上下文菜单。

So what is

那是什么

 - not an application that has to run in the background constantly, or take time to launch

-不是必须经常在后台运行或需要花费时间才能启动的应用程序

 - not a clipboard replacement or extenstion

-不是剪贴板的替换或扩展

 - not a sendkeys or macro kludge

-不是sendkeys或巨集

 ...that can provide a simple bridge to the clipboard?

...可以为剪贴板提供一个简单的桥梁?

 The answer, pretty much, is either

答案几乎是

a DLL Wrapper for copy/paste api's in Windows

Windows中用于复制/粘贴api的DLL包装器

 OR

要么

 ...a shell extension.

... 外壳扩展

My favorite choice here, what I think would be perfect for this job and really is needed for other things in Windows too, would be a DLL Wrapper.  Alas, after much searching it appears I am going to have to write the darned thing myself.  I did write one once, and I think I should write this one, but there's no time for that right now (too much learning time to allocate to that project, so later for that).

我最喜欢的选择是DLL Wrapper,这对我来说是完美的选择,而Windows中其他方面也确实需要这样做。 las,经过大量搜索,看来我将不得不自己写点老实的东西。 我确实写过一次,我想应该写这篇,但是现在没有时间(分配给该项目的学习时间太多,所以以后再写)。

-------------------

-------------------

All righty then, looks like I need to figure a solution utilizing (or coding) some sort of shell extension.  (Yeah, like coding that will take any less effort...)

好吧,看来我需要找到一个利用(或编码)某种外壳扩展的解决方案。 (是的,就像编码将花费更少的精力...)

As it turns out, you can create your own "Copy to" and "Move to" context menu commands with some simple registry editing; however, then you need to figure out how to leaverage those within your script.  Since they are not simple commands this is going to take a little work to sort out.

事实证明,您可以通过简单的注册表编辑来创建自己的“复制到”和“移动到”上下文菜单命令 。 但是,那么您需要弄清楚如何对脚本中的内容进行烦恼。 由于它们不是简单的命令,因此需要花费一些时间进行整理。

But Wait... well, duh, there are already several free "Send to" shell extensions out there... maybe one of those is the ticket!

但是等等...嗯,嗯,那里已经有几个免费的“发送到” shell扩展了……也许其中之一就是门票!

===========================

========================= =

THE SOLUTION

解决方案

Indeed, what I ended up doing is setting up a sendto extension that my script could talk to for copying and/or moving a system object.

确实,我最终要做的是设置一个sendto扩展,我的脚本可以与该sendto扩展进行对话以复制和/或移动系统对象。

Here's the flow-chart and explanation of how this works.  The example script appears below.

这是流程图和解释方式。 示例脚本如下所示。

This soluton that seemed so tough to suss (a week of searching turned up nothing but similar questions with half-baked answers), but turns out to be rather simple.

这种似乎很难解决的解决方案(经过一周的搜索,除了类似的问题和半生半熟的答案外,什么都没有发现),但事实证明这很简单。

- A shortcut to the below script is placced in the Sendto folder so one can simply: select the desired files, right-click on the selection and then drop it onto the script within the 'Send To' context-menu simply by selecting it.

-Sendto文件夹中提供了以下脚本的快捷方式,因此可以轻松执行以下操作:选择所需的文件,右键单击所选内容,然后将其拖放到“发送至”上下文菜单中的脚本中。

 - The script takes all the files dropped onto it as a delimited argument list !

-该脚本将所有放在其上的文件作为分隔的参数列表!

 - The list is parsed for shortcuts, i.e., iterated in order to catch the shortcuts and convert those list items into their 'target constituents'.

-解析列表中的快捷方式,即进行迭代以捕获快捷方式并将这些列表项转换为它们的“目标组成部分”。

 - The list is reassembled into a collection of the files we want to copy or move

-列表重新组合成我们要复制或移动的文件的集合

 - Finally, the new list is passed on to whatever favorite shell extension (or application or utility) we may be vested in for Copying/Moving FileSyustem Objects.

-最后,新列表将传递给我们可能喜欢用于复制/移动FileSyustem对象的任何常用的Shell扩展(或应用程序或实用程序)。

  You simply navigate to and select your intended directory destination  

您只需导航到并选择您想要的目录目标

 ...and all those files get copied/moved there

...所有这些文件都被复制/移动到那里

 - Using the method shown here we can use vbscript/wscript/cscript/powershell for custom-assembling a file system objects collection (i.e., via simple user selection) and handing that off to any application that can handle file system object pointers... so this can actually be quite powerful (well beyond the scope of simple copying/moving files).

-使用此处显示的方法,我们可以使用vbscript / wscript / cscript / p 用于自定义组装文件系统对象集合(即通过简单的用户选择)并将其交给可以处理文件系统对象指针的任何应用程序的强大外壳……因此,它实际上非常强大(远远超出了简单复制的范围) /移动文件)。

-------

-------

 So say you have a folder where you have collected a bunch of shortcuts to files residing in different places on your hard drive and you want to copy those files (not the shortcuts) onto a USB stick or other Drive... this method can accomplish that for you in a couple clicks.

假设您有一个文件夹,其中收集了许多位于硬盘驱动器上不同位置的文件的快捷方式,并且要将这些文件(而不是快捷方式)复制到USB记忆棒或其他驱动器上...此方法可以完成几次点击即可为您找到。

 Say you are staring at a shortcut on your desktop whose target file you want to move or copy to an alternate location... couple clicks, done.

假设您正在盯着桌面上的快捷方式,您要将其目标文件移动或复制到其他位置...几次单击完成。

 Say you have a folder with a mix of some files and some shortcuts to other files, and you want to collect those files and target files all into some folder somewhere else... this is the only thing I know of that will do that in a simple couple clicks.

假设您有一个包含一些文件和一些指向其他文件的快捷方式的文件夹,并且要将这些文件和目标文件全部收集到其他位置的某个文件夹中……这是我所知道的唯一一件事简单的几次点击。

======================================================

========================= ========== ========== ========

THE SAMPLE CODE

样本代码

The following example is only intended to provide a model insight into how one might tackle the problem of copying/moving file system objects with simple scripting considering the limitations we are handed in MS Windows.

考虑到我们在MS Windows中遇到的局限性,以下示例仅旨在提供一种模型洞察力,以了解如何通过简单的脚本解决复制/移动文件系统对象的问题。

Based on the following, it should be possible to elaborate on this code (quite simply) to create a script for also handling Folders and SubFolders and their collections.

基于以下内容,应该有可能对此代码进行详细说明(非常简单)以创建一个脚本,用于处理Folders和SubFolders及其集合。

I hope you find this information, along with the following example, insightful and useful.

希望您能从以下示例中找到有用且有用的信息。

Cheers,

干杯,

TwoHawks

两次鹰

***PS: If you figure out how to set this up (in the registry) with its own ContextMenu item  --that actually works-- I would really be interested in hearing about that, as well as any other potentially relevant wrapper, shell extension, or PowerShell script being shared for assisting scripts to interface with the Windows Clipboard for handling file system objects (not text or file contents, but files and folders and the like) !

*** PS:如果您想出如何使用其自己的ContextMenu项(在注册表中)进行设置的方法,该菜单项实际上是有效的,那么我真的很想了解此信息以及任何其他可能相关的包装器,外壳程序扩展名或共享的PowerShell脚本,以帮助脚本与Windows剪贴板交互以处理文件系统对象(不是文本或文件内容,而是文件和文件夹等)!

' BEGIN SCRIPT.
' TwoHawks' Simple CopyTargetFiles.vbs script
' Free to Use ...at your own risk, of course ;^)

' The code here is set up to provide information about what is being passed/parsed via alerts.
' Of course, none of the alerts are necessary for the code to carry out its primary function
' You should test carefully before presuming to implement this method as a solution on your system
' This example currently handles only files, and shortcuts to files, and is NOT setup for handling FOLDERS !
' Copy into a file, say, CopyTargetFiles.vbs and place a shortcut into your SendTo Folder

Set WSHELL = Wscript.CreateObject("Wscript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

Dim ARG()
Dim ARGS()
WScript.Echo "The Number of Items Passed is: " & Wscript.Arguments.Count

For i = 0 to Wscript.Arguments.Count - 1
  'Enumerate the collection and provide details of each item
  Redim Preserve ARG(i)
  ARG(i) = Wscript.Arguments(i)
  Wscript.Echo "Current Argument String: " & ARG(i)

  'Obviously there are various ways to handle looking at the filesystem object properties...
  Set f = FSO.GetFile(ARG(i))
  FileName=f.Name
  FilePath=f.Path
  Wscript.Echo ("File : " & f)
  Wscript.Echo ("FileType : " & f.type)
  Wscript.Echo ("FilenameObj: " & FileName)
  Wscript.Echo ("FilePathObj: " & FilePath)
  
  'Transform List-Item Links into their actual targets
  fExt = FSO.GetExtensionName(ARG(i))
  Wscript.Echo ("FileExtension is : " & fExt)
  ifExt = StrComp(fExt, "LNK", vbTextCompare)
  IF ifExt = 0 THEN
    set oSHLink = WSHELL.CreateShortcut(FilePath)
    target = oSHLink.TargetPath
    Set f = FSO.GetFile(target)
    Wscript.Echo "Target is : " & target
    Wscript.Echo "New File is : " & f
    Wscript.Echo ("FileType : " & f.type)
  End If

  'Recreate a new collection containing all hard targets (no links)
  Redim Preserve ARGS(i)
  ARGS(i) = f
  Wscript.Echo ("ARGS Array is now: " & Join(ARGS," "))
  Wscript.Echo ("ARG Array is now: " & Join(ARG," "))
  
Next

' Now send this off to a Shell Extension for Copying/Moving file system objects
' Note: Usually you send a list of arguments to an application separated by a space ;^)
' So if you use this for other application you need to be mindful of the correct/expected delimiter
WSHELL.Run (chr(34) &  "C:\Program Files\Send To Toys\SendToFolder.exe"  &  chr(34) & Join(ARGS," ") &  chr(34) & chr(34))

Set oSHLink = Nothing
Set FSO = Nothing
Set WSHELL = Nothing
Wscript.Quit
' END SCRIPT

翻译自: https://www.experts-exchange.com/articles/2642/Script-to-copy-or-move-collection-of-selected-files-plus-shortcut-target-files-referenced-by-lnk.html

如何指定lnk文件的目标

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值