[英]Command Line Works - .Bat Script Doesn't
When attempting to run the following commands via the cmd prompt on a windows 2008 server everything works successfully. 尝试通过Windows 2008服务器上的cmd提示符运行以下命令时,一切都将成功运行。 However once those same commands are saved to a .bat or .cmd file the script no longer works. 但是,将这些相同的命令保存到.bat或.cmd文件后,该脚本将不再起作用。
@echo off
set FILE="\\servername\c$\users\users\desktop\test.txt"
FOR %I in (%FILE%) DO set SIZE=%~ZI
IF %SIZE% == 75 (
copy "\\servername\c$\users\users\desktop\test.txt" "\\servername\c$\users\users\desktop\test-1.txt"
del "\\servername\c$\users\users\desktop\test.txt"
) ELSE (
echo "Failure"
)
TIMEOUT /T -1
I'm not sure what the difference would be and would appreciate any help that can be provided. 我不确定会有什么不同,将不胜感激。 The text file I'm using has the following text in it. 我正在使用的文本文件中包含以下文本。
" “
hello goodmorning 你好,早上好
I need this to have a file size. 我需要这个文件大小。
this file size is 75 该文件大小为75
" “
在批处理脚本中, for
循环的变量需要两个%
符号。
FOR %%I in (%FILE%) DO set SIZE=%%~ZI
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.