【问题标题】:I need help to "fine tune" my batch script (adding IF statements)我需要帮助来“微调”我的批处理脚本(添加 IF 语句)
【发布时间】:2013-05-26 09:12:08
【问题描述】:

我必须:

  1. 将 .doc 文件从一个位置复制到另一个位置
  2. 在新位置重命名(将当前日期添加到名称中)
  3. 打开复制/重命名文件现在所在的位置
  4. 播放确认音

下面的(基本)批处理脚本依赖于小型播放器 (BP) 来播放声音,非常适用于上述 4 点。

@echo off
xcopy "C:\Some Path\Doc.doc" "D:\My Documents\" /q /y /k /r /h
ren "D:\My Documents\Doc.doc" "New Word Document (%date%).doc"
ping -n 3 127.0.0.1 > nul
start "" /b /wait "D:\My Documents\"
BP /play /close /embedding .\1.wav
exit

我想请一位(不像我)熟悉脚本的人帮助我添加一些 IF 语句,即:

  • 参考上述第 2 点:如果该位置已存在 "New Word Document (%date%).doc" 文件,则应跳过 xcopy 和 ren 命令(但应继续执行其余命令)。

和

  • 参考上面的第 3 点:如果文件夹 "D:\My Documents\" 已打开,则应跳过 start 命令(但应继续执行其余命令)。

提前感谢您的帮助

【问题讨论】:

    标签: batch-file windows-xp


    【解决方案1】:

    根据How to verify if a file exists in a Windows .BAT file?和If Not Exist - CMD Command - Not Working

    IF NOT EXIST "D:\My Documents\New Word Document (%date%).doc" (
      xcopy "C:\Some Path\Doc.doc" "D:\My Documents\" /q /y /k /r /h
      ren "D:\My Documents\Doc.doc" "New Word Document (%date%).doc"
    )
    

    根据"Bring to front" for Windows XP command shell,第二部分你似乎不走运

    【讨论】:

    • @Micha:感谢您为我指明正确的方向以及您提供的链接(不错的提示)。
    • 感谢您的提示,我改进了我的脚本,如下所示: IF EXIST "D:\My Documents\New Word Document (%date%).doc" (goto PLACE) else goto OTHER PLACE...这样我就更开心了:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多