用于多次重命名文件的批处理脚本

时间:2013-08-13 15:18:43

标签: time batch-file rename

我正在尝试创建一个批处理脚本,它将成为关闭脚本的开/关开关。

基本上通过重命名来打开和关闭在任务计划上运行的关闭脚本。所以我有两个选项,一个将它从原始名称重命名为其他东西以停止任务计划触发,另一个通过将名称更改为原始名称来重新打开它。

现在,这个工作一次,但是如果我再试一次,就不会发生任何事情。

我哪里错了?

:选项1

rename C:\Users\user\Desktop\shutdown.bat shutdown1.bat 

1:选项

rename C:\Users\user\Desktop\shutdown1.bat shutdown.bat

2 个答案:

答案 0 :(得分:0)

您不应该将代码发布为答案...

问题是,在选择:Selection2时,您不会跳过Selection1。您必须在GOTO :Quit

之前加:Selection2

答案 1 :(得分:0)

继承整个代码

@ECHO OFF
C:
CD\
CLS

:MENU
CLS

ECHO ============= MENU NAME =============
ECHO Select an option from below by typing the corresponding number.
ECHO _
ECHO 1.  Turn ON Auto Night Shutdown
ECHO 2.  Turn OFF Auto Night Shutdown
ECHO -------------------------------------
ECHO ==========PRESS 'Q' TO QUIT==========
ECHO.

SET INPUT=
SET /P INPUT=Please select a number:

IF /I '%INPUT%'=='1' GOTO Selection1
IF /I '%INPUT%'=='2' GOTO Selection2
IF /I '%INPUT%'=='Q' GOTO Quit

CLS

ECHO ============INVALID INPUT============
ECHO -------------------------------------
ECHO Please select a number from the Main
echo Menu [1-2] or select 'Q' to quit.
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======

PAUSE > NUL
GOTO MENU

:Selection1

rename C:\Users\user\Desktop\shutdown.bat shutdown1.bat 

 :Selection2

rename C:\Users\user\Desktop\shutdown1.bat shutdown.bat

 :Quit
  CLS

  ECHO ==============SUCCESS===============
  ECHO -------------------------------------
  ECHO ======PRESS ANY KEY TO CONTINUE======

  PAUSE>NUL
   EXIT