很实用的一个设置。我们知道,Windows 中的路径是使用\分割的,但\在大多数编程语言中被用于转义字符,这使得在 Windows 下复制的路径字符串都不能直接在程序中使用,需要手动把\替换成/,使用/分割的路径在绝大多数编程语言中是合法,这种格式的路径也是一种标准,称为:URI (统一资源标识符)。完整的 URI 路径一般会在前面加上 shema,例如:file:///C:/Users/abc/test.txt,这下,可能很多人就眼熟了。
如果我们经常需要获取本地目录的 URI 路径,可以修改注册表,填加一下右键菜单:复制 URI 路径,可在目录空白处或目录、文件上直接右键获取,如下图这样:
打开文本编辑器,粘贴如下内容:
Windows Registry Editor Version 5.00 ; 文件右键 [HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\CopySlashPath] @="复制 URI 路径" "Icon"="shell32.dll,-16758" [HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\CopySlashPath\command] @="powershell -WindowStyle Hidden -NoProfile -Command \"$path='%1';$path=$path.Replace('\\\\','/');Set-Clipboard -Value $path\"" ; 文件夹右键 [HKEY_CLASSES_ROOT\Directory\shell\CopySlashPath] @="复制 URI 路径" "Icon"="shell32.dll,-16758" [HKEY_CLASSES_ROOT\Directory\shell\CopySlashPath\command] @="powershell -WindowStyle Hidden -NoProfile -Command \"$path='%1';$path=$path.Replace('\\\\','/');Set-Clipboard -Value $path\"" ; 文件夹空白处右键(复制当前目录) [HKEY_CLASSES_ROOT\Directory\Background\shell\CopySlashPath] @="复制 URI 路径" "Icon"="shell32.dll,-16758" [HKEY_CLASSES_ROOT\Directory\Background\shell\CopySlashPath\command] @="powershell -WindowStyle Hidden -NoProfile -Command \"$path=(Get-Location).Path;$path=$path.Replace('\\\\','/');Set-Clipboard -Value $path\""保存为一个 reg 文件,如:AddSlashPath.reg,然后双击文件,导入到注册表中。重启 Windows 资源管理器进程,确保修改生效,然后就可以看到右键菜单了。