gpt4 book ai didi

batch-file - 从上下文菜单复制文件的父目录路径

转载 作者:行者123 更新时间:2023-12-01 22:06:26 24 4
gpt4 key购买 nike

我正在学习批处理脚本,因为它对于设置 Windows 用户选择的一些快速自定义上下文菜单选项以获取文件及其父目录路径非常有用。

现在我知道以下命令将传递的参数作为文件路径并将其复制到剪贴板:

cmd /c (echo.|set /p=""%1"") | clip

但是为什么在上下文菜单中设置时以下语法没有按预期工作?

cmd /c (echo.|set /p=""%~dp1"") | clip

这是变量扩展问题吗?请指导它为什么不起作用以及如何解决它以使其正常扩展。

注册表项示例,其中我永久设置要运行的命令,带有开关、变量扩展等。

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\*\shell\Copy File's Parent Path]
@="Copy File's Parent Path"

[HKEY_CURRENT_USER\Software\Classes\*\shell\Copy File's Parent Path\Command]
@="cmd.exe /c (echo.|set /p=\"\"%~dp1\"\") | clip"

最佳答案

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\*\shell\Copy Files Path\command]
@="cmd /c (echo. | set /p =\"\"%1\"\") | clip"

[HKEY_CURRENT_USER\Software\Classes\*\shell\Copy Files Parent Path\command]
@="cmd /c (echo. | set /p =\"\"%w\"\") | clip"

%1 替换为 %w。 2个注册表项来演示%1 作为 Copy Files Path%w 作为 Copy Files Parent Path

引用自Extending Shortcut Menus在页面底部。

%0 or %1  the first file parameter. For example “C:\Users\Eric\Desktop\New Text Document.txt”. Generally this should be in quotes and the applications command line parsing should accept quotes to disambiguate files with spaces in the name and different command line parameters (this is a security best practice and I believe mentioned in MSDN).%N  (where N is 2 - 9), replace with the nth parameter%*  replace with all parameters%~  replace with all parameters starting with and following the second parameter%d  desktop absolute parsing name of the first parameter (for items that don’t have file system paths)%h  hotkey value%i  IDList stored in a shared memory handle is passed here.%l  long file name form of the first parameter. Note win32 applications will be passed the long file name, win16 applications get the short file name. Specifying %L is preferred as it avoids the need to probe for the application type.%s  show command%v  for verbs that are none implies all, if there is no parameter passed this is the working directory%w  the working directory

关于batch-file - 从上下文菜单复制文件的父目录路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51452418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com