batch-file - 文件夹右键菜单的 Windows 10 批处理脚本工作目录
问题描述
我想要做的是我需要创建一个以今天日期为名称的文件夹以用于存档目的。所以我创建了一个脚本来做到这一点并且它正在工作。现在我想将此脚本批处理文件添加到文件夹右键菜单中,以便我可以单击它,它将在我单击的位置自动创建该文件夹。所以我在我的注册表中创建了一个键,如下所示:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\Today Directory script]
@="&Today Directory script"
[HKEY_CLASSES_ROOT\Directory\Background\shell\Today Directory script\command]
@="C:\\Scripts\\TodayDir.bat \"%V\""
现在该命令出现在菜单中。
这是脚本的代码:
@ECHO OFF
REM Gets the working folder from where the click came from and removes the last slash (\)
for %%Q in ("%~dp1\.") DO set "mypath=%%~fQ"
REM Checks when the wroking directory is from. Local drive or network drive
if %mypath:~0,1%==c (goto cdrive) else ( goto networkdrive)
REM Code to create directory in a local drive
:cdrive
MD %mypath%\%DATE%
exit
REM Code to create directory in a network drive by assigning a drive letter to the path,
REM create the directory, delete the drive assigment.
:networkdrive
net use p: "%mypath%"
MD p:\%DATE%
net use p: /delete
exit
此代码工作正常,但在从上方的右键菜单触发时无法正常工作。它没有获取工作目录("%~dp1\."
命令)的路径。如果我这样做,"%~dp0\."
我会得到批处理文件所在的路径 (C:\Scrpits)。
如何从右键菜单中获取单击的目录?
谢谢,
丹尼斯
新信息:
这是创建的注册表项:
"%ProgramFiles%\Easy Context Menu\EcMenu.exe" /RunAdmin "%SystemRoot%\system32\cmd.exe" /s /k pushd "%V"
当 cmd.exe shell 打开时,我得到这个 mwssage:
'\\lofthouse1\Tool' CMD.exe was started with the above path as the current directory. UNC paths are not supported. Defaulting to windows directory.
我需要更改注册表以使 cmd.exe 接受 pushd 目录名称吗?
丹尼斯
解决方案
推荐阅读
- javascript - this.$refs.myProperty.refresh 不是函数
- c++ - 不接受字母表字母的条件
- javascript - 页面上的 JavaScript 验证错误,但可以转到下一步
- go - 设置模块 url:没有 go-import 元标记
- javascript - 当前一个成功完成时,如何对 api 进行新的调用?
- wordpress - 了解 WordPress 开发
- c# - Automapper - 为什么不使用 SourceMember 属性进行映射
- string - 如何在另一个函数中使用 Ruplacer (Rust)
- flutter - 冻结 - 没有为 x 定义 getter 'x'
- java - 即使列表中的一个 CompletableFuture 尚未完成,CompletableFuture.allOff 也会完成