用于复制所选文件的“自定义上下文菜单"选项无法正常工作 [英] Custom Context Menu option for duplicating selected file not working as expected

查看:32
本文介绍了用于复制所选文件的“自定义上下文菜单"选项无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个自定义上下文菜单选项,用于复制所选文件并将日期和时间字符串附加到复制文件的名称上.

I am trying to create a custom Context Menu option for duplicating the selected file and appending date and time string to the copied file's name.

下面是我在注册表中设置的命令,在HKCU>软件>类> *> Shell>复制此文件>命令:

Below is the command I have set in registry, in the HKCU > Softwares > Classes > * > Shell > Duplicate This File > Command:

cmd /s /d /c @echo off & setlocal EnableExtensions EnableDelayedExpansion & set TIME=%TIME: =0% & set DateTimeFn=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2%_!TIME:~0,2!-!TIME:~3,2!-!TIME:~6,2! & copy /y %1 %1_!DateTimeFn! & pause > nul

但是由于某种原因,enabledelayedexpansion无法正常工作,因为当我尝试在文件 test.js 上使用它时,它会将其复制为 test.js_!DateTimeFn!.

But somehow the enabledelayedexpansion doesn't work correcty, cause when I try to use this on file test.js it duplicates it as test.js_!DateTimeFn!.

此外,它不能与文件名中的空格一起使用.谁能指导和帮助解决此问题?

Also it doesn't work well with spaces in filenames. Can anyone guide and help fix this ?

在可能的情况下,我更喜欢单行而不是创建单独的批处理脚本.

I would prefer one-liner over creating separate batch script as far as it's possible.

我尝试在其中使用开关和变量扩展名运行命令的注册表文件示例:

Sample of registry file in which I am trying to run the command with switches and variable expansions:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\*\shell\Duplicate This File II]

[HKEY_CURRENT_USER\Software\Classes\*\shell\Duplicate This File II\command]
@="cmd /v:on /c @echo off & set TIME=%TIME: =0% & set DateTimeFn=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2%_!TIME:~0,2!-!TIME:~3,2!-!TIME:~6,2! & copy /y %1 %1_!DateTimeFn! & pause > nul"

推荐答案

您将需要在FOR命令中使用该参数,然后可以使用命令修饰符将文件名与扩展名分开.

You will need to use the argument in a FOR command and then you can use the command modifiers to get the file name separated from the extension.

cmd /Q /V:ON /E:ON /C "set TIME=%%TIME: =0%% & set DateTimeFn=%%DATE:~10,4%%-%%DATE:~4,2%%-%%DATE:~7,2%%_!TIME:~0,2!-!TIME:~3,2!-!TIME:~6,2! &FOR %%G IN ("%1") do copy "%1" "%%~nG_!DateTimeFn!%%~xG" & pause>nul"

这是实际的注册表导出.

Here is the actual registry export.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\*\shell\Time_Stamp_FileName]

[HKEY_CURRENT_USER\Software\Classes\*\shell\Time_Stamp_FileName\command]
@="cmd /Q /V:ON /E:ON /C \"set TIME=%%TIME: =0%% & set DateTimeFn=%%DATE:~10,4%%-%%DATE:~4,2%%-%%DATE:~7,2%%_!TIME:~0,2!-!TIME:~3,2!-!TIME:~6,2! &FOR %%G IN (\"%1\") do copy \"%1\" \"%%~nG_!DateTimeFn!%%~xG\" & pause>nul\""

这篇关于用于复制所选文件的“自定义上下文菜单"选项无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆