简体   繁体   中英

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. However once those same commands are saved to a .bat or .cmd file the script no longer works.

@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
"

在批处理脚本中, for循环的变量需要两个%符号。

FOR %%I in (%FILE%) DO set SIZE=%%~ZI

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM