从Windows资源管理器的“发送到"菜单中调用powershell命令
我创建了一个powershell脚本,该脚本会将选定的文件复制到预定位置.
我已经创建了一个批处理文件,以从Windows资源管理器的发送到"菜单中调用Powershell脚本.
批处理文件将所选文件名作为参数发送到脚本.文件名可以包含空格.
批处理文件代码为
I have created a powershell script that will copy selected files to predetermined location.
I have created a batch file to call the Powershell script from Windows Explorer "Send to" menu.
The batch file sends the selected file name as a parameter to the script. The file names can contain spaces.
The batch file code is
powershell "C:\copycommand.ps1 '%1'"
当选择了多个文件我想给所有的文件名作为数组的PowerShell脚本.点击 我已经编写了Powershell脚本来接受数组,但是无法从批处理文件中将文件名作为数组发送.
When multiple files are selected I want to send all the file names as an array to the powershell script.
I have written the powershell script to accept arrays but I am not able to send the file names as an array from the batch file.
下面的批处理脚本将所有文件名发送到批处理文件,但是当文件名包含空格时失败.
The below batch script sends all the filenames to the batch file but fails when the filename has spaces.
Powershell "C:\copycommand.ps1" %*
有没有一种方法可以将所有文件名发送到Powershell脚本.
Is there a way in which I can send all the filenames to the powershell script.
我的bat文件看起来像(最后一行仅用于调试,您可以将其删除):
My bat file looks like (the last line is only for debugging, you can remove it):
@echo off
for %%x in (%*) do (
powershell.exe -Command "C:\copycommand.ps1 '%%x'"
)
powershell.exe -noexit
我的powershell脚本是:
My powershell script is:
$args | %{ Write-host "do copy $_"}
示例输出为:
do copy C:\Users\Public\Desktop\SRWare Iron.lnk
do copy C:\Users\Public\Desktop\Mozilla Firefox.lnk
do copy C:\Users\Piotrek\Desktop\Windows 7 USB DVD Download Tool.lnk
更新版本
将bat文件更改为:
@echo off
set myvar=
for %%x in (%*) do call :concat %%x
echo %myvar%
powershell.exe -Command C:\copycommand.ps1 %myvar%
powershell.exe -noexit
goto :eof
:concat
set myvar=%myvar% '%1'
goto :eof