Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 在cmd提示符中将字符串设置为localdatetime_Windows_Batch File_Cmd_Command_Command Prompt - Fatal编程技术网

Windows 在cmd提示符中将字符串设置为localdatetime

Windows 在cmd提示符中将字符串设置为localdatetime,windows,batch-file,cmd,command,command-prompt,Windows,Batch File,Cmd,Command,Command Prompt,我在运行时遇到以下异常: for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j %%此时我出乎意料。 我想运行的整个脚本是: echo Step 2 of 8: Backing up files in target directory to an archive directo

我在运行时遇到以下异常:

for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
%%此时我出乎意料。

我想运行的整个脚本是:

echo Step 2 of 8: Backing up files in target directory to an archive directory with a timestamp (ldt) in the name...
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%_%ldt:~8,2%%ldt:~10,2%%ldt:~12,6%
if exist "%APPLICATION_FILES_TARGET_DIR%" xcopy "%APPLICATION_FILES_TARGET_DIR%\*.*" "%APPLICATION_FILES_ARCHIVE_DIR%_%ldt%\*.*" /e /f /y
我正在尝试备份名为MyDirectory的目录,方法是制作一份完整的目录副本,并将其命名为backup\u MyDirectory\u 2016-02-03\u 112932.940


我做错了什么?意外异常的含义是什么?

奇怪,这应该完全有效。事实上,它在我的电脑上运行得很好。我注意到您没有在任何地方设置
%APPLICATION\u FILES\u TARGET\u DIR%
。。。我知道你说那是你的全部剧本,但是你的剧本还有其他的吗?它是否被另一个脚本调用?那个位在另一个
for
循环中吗?我总是这样做的
for/F“tokens=2 delims==”%%i in('wmic os get LocalDateTime/VALUE')do set ldt=%%i
%%i
只能在批处理文件中工作,在命令行上必须使用
%i
@jeb您完全正确,您能给我一个源代码吗?您只需要查看标准帮助的第3段(
help for
for/?
):“要在批处理程序中使用for命令,请指定%%variable而不是%variable。”