将所选文件的名称从发送到“发送到” powershell脚本的菜单

发布于 2025-02-08 01:18:50 字数 177 浏览 1 评论 0原文

我的脚本已经添加到“发送到”菜单中,它要求搜索字符串,然后在该目录中的每个.log和.txt文件搜索字符串中的每个.log和.txt文件。

但是我需要做的是查看我右键单击并收集名称的文件,以便我可以用作唯一要搜索的文件。

因此,如果您可以帮助我抓住文件的名称上,然后“发送到”我的PowerShell脚本。 谢谢

I have a script that I wrote that is added to the "Send To" menu already, and it asks for a search string and then searches every .log and .txt file in that directory for the string.

But what I need it to do is look at the file I am right clicking on and collect the name so I can use it as the only file to search in.

So if you can help me grab the name of the file I am right clicking on, and then "send to" my PowerShell script.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吹泡泡o 2025-02-15 01:18:50

在您的“ sendto”文件夹中创建快捷方式:

  • win+r ,enter shell:sendto
  • 使用此目标创建快捷方式:
    • 用于Windows PowerShell:
       “%systemRoot%\ system32 \ windowspowershell \ v1.0 \ powershell.exe” -file“ fullpathtoyourscript.ps1”
       
    • 对于PowerShell 7+:
       “%programFiles%\ powershell \ 7 \ pwsh.exe” -file“ fullpathtoyourscript.ps1”
       

调用“发送到”菜单项时,系统将所选文件的完整路径附加到命令行。在您的PowerShell脚本中,使用自动$ args数组变量以从命令行参数获取文件路径。

此演示显示了如何获取所选文件的数量并循环通过路径:

"Received $($args.Count) files:"

foreach( $path in $args ) {
    "Processing file: $path"    
}

Create a shortcut in your "SendTo" folder:

  • Press Win+R, enter shell:sendto
  • Create a shortcut with this target:
    • for Windows PowerShell:
      "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -File "FullPathToYourScript.ps1"
      
    • for PowerShell 7+:
      "%ProgramFiles%\PowerShell\7\pwsh.exe" -File "FullPathToYourScript.ps1"
      

When the "Send to" menu item is invoked, the system appends the full paths of the selected files to the commandline. In your PowerShell script, use the automatic $args array variable to get the file paths from the commandline arguments.

This demo shows how you can get the number of selected files and loop over the paths:

"Received $($args.Count) files:"

foreach( $path in $args ) {
    "Processing file: $path"    
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文