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

2023-12-10

我正在学习批处理脚本,因为它对于设置 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"

Replace %1 with %w。 2个注册表项来演示%1 as Copy Files Path and %w as Copy Files Parent Path.

参考自扩展快捷菜单在页面底部。


%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
  
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从上下文菜单复制文件的父目录路径 的相关文章

随机推荐