批处理之家's Archiver

aa77dd@163.com 发表于 2016-10-23 15:17

cmd+clip实现右键菜单(Context menu)复制单文件/目录路径到剪贴板 for Win 7

[i=s] 本帖最后由 aa77dd@163.com 于 2016-10-23 15:32 编辑 [/i]

Win 7 系统下, 按住 Shift 键, 在文件/目录上右击的菜单中, 有一个

copy as path (中文系统: 复制为路径) 的功能, 此功能支持多个文件/目录对象, 无论路径中有无空格, 所有路径都会被加上双引号

path copy copy 是一个此功能的第三方工具, 有更大的扩展, 不用按住 Shift, 支持多文件/目录, 有许多选项可以自定义, 比如是否加双引号

如果不想安装 path copy copy 之类第三方工具, 也不需要同时复制多文件/目录的路径, 也不想要双引号,

cmd + clip 就能实现, 测试于 中文 Win 7 64 位

将下面批处理代码保存并运行, 安装选 S, 卸载选 D, 安装完成后, 批处理文件不需用到, 右键菜单出来后, 此功能的快捷键是 F

注册表中的功能实现命令是调用 cmd.exe 和 clip.exe 达成

[img]https://ooo.0o0.ooo/2016/10/23/580c62da151ff.png[/img]  [img]https://ooo.0o0.ooo/2016/10/23/580c62de303fc.png[/img][code]Windows Registry Editor Version 5.00 2> nul
; @echo off & cls & if "%~1"=="" (goto :choose) else goto :processPath
[HKEY_CLASSES_ROOT\*\shell\CopyPathForSingleFile_Folder]
@="copy path for single (&F)ile/Folder"

[HKEY_CLASSES_ROOT\*\shell\CopyPathForSingleFile_Folder\command]
@="cmd.exe /c <nul set /p \"=%V\"|clip"

[HKEY_CLASSES_ROOT\Directory\Shell\CopyPathForSingleFile_Folder]
@="copy path for single (&F)ile/Folder"

[HKEY_CLASSES_ROOT\Directory\Shell\CopyPathForSingleFile_Folder\Command]
@="cmd.exe /c <nul set /p \"=%V\"|clip"

:processPath

;<nul set /p "=%*"|clip

;exit


:choose
;echo;COPY PATH FOR SINGLE FILE/FOLDER
;echo;          S    SETUP
;echo;          D    DELETE
;<nul set /p "=Please choose:"
;call :GetKey
;echo;[%key%]

;if /i "%key%"=="s" goto :SetupMe
;if /i "%key%"=="d" goto :DeleteMe
;echo;choose error
;pause
;exit


:SetupMe
;echo;Setup copy path for single file/folder ...
;regedit /s "%~f0"
;rem degug mode
;rem reg add "HKCR\*\shell\CopyPathForSingleFile_Folder\command" /ve /f /d "cmd.exe /k \"%~f0\" %%1"
;rem reg add "HKCR\*\shell\CopyPathForSingleFile_Folder\command" /ve /f /d "cmd.exe /c <nul set /p \"=%%V\"|clip"
;rem reg add "HKCR\Directory\Shell\CopyPathForSingleFile_Folder\command" /ve /f /d "cmd.exe /c <nul set /p \"=%%V\"|clip"
;echo;SETUP COMPLETE, PRESS ANY KEY TO EXIT...
;>nul pause
;exit


:DeleteMe
;reg delete HKCR\*\shell\CopyPathForSingleFile_Folder /f
;reg delete HKCR\Directory\Shell\CopyPathForSingleFile_Folder /f
;echo;UNINSTALL COMPLETE, PRESS ANY KEY TO EXIT...
;>nul pause
;exit


:GetKey
;set "key="
;for /F "usebackq delims=" %%L in (`xcopy /w . 2^>nul`) do (
;  if not defined key set "key=%%L"
;)
;set "key=%key:~-1%"
;exit /b
[/code]或者只用其中包含的注册表脚本也可以安装[code]Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\CopyPathForSingleFile_Folder]
@="copy path for single (&F)ile/Folder"

[HKEY_CLASSES_ROOT\*\shell\CopyPathForSingleFile_Folder\command]
@="cmd.exe /c <nul set /p \"=%V\"|clip"

[HKEY_CLASSES_ROOT\Directory\Shell\CopyPathForSingleFile_Folder]
@="copy path for single (&F)ile/Folder"

[HKEY_CLASSES_ROOT\Directory\Shell\CopyPathForSingleFile_Folder\Command]
@="cmd.exe /c <nul set /p \"=%V\"|clip"[/code]

wskwfkbdn 发表于 2016-10-23 16:44

+1























·

GNU 发表于 2016-10-23 17:03

人生苦短,我选择使用 Total Commander [img]http://bbs.bathome.net/images/smilies/default/lol.gif[/img]

codegay 发表于 2016-10-23 19:19

如果不能弹出窗口的话,应该会好很多。

Bella 发表于 2016-10-25 22:22

这图床的作者和我说流量根本用不完, 那还客气什么
你这字体典型的没开 平滑字体边缘
[img]https://ooo.0o0.ooo/2016/10/25/580f69fa09ab8.png[/img]

aa77dd@163.com 发表于 2016-10-25 23:04

[b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=192192&ptid=42124]5#[/url] [i]Bella[/i] [/b]

亲分享的这图床, 我可真喜欢, 又好用, 域名也那么厉害, 太棒了,:victory:  
平滑字体边缘 这个效果, 我以前一直也不知道是啥样的, 刚刚才好好瞅了一下, 发现桌面上的文字有了阴影, 呵呵, 应该不止这一点儿吧, 哈哈

Bella 发表于 2016-10-25 23:14

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=192193&ptid=42124]6#[/url] [i]aa77dd@163.com[/i] [/b]


    那是图标的标签阴影, 不纠结这个问题了, 哈哈

eech 发表于 2019-8-25 15:57

用了楼主的脚本,就是会有个DOS窗口闪过,楼主能不能改良个VBS版的,这样就没窗口了,感谢楼主的大作

eech 发表于 2021-7-20 00:15

只想问一句,win10能用吗?

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.