2013-05-26 46 views
1

我已经到:我需要帮助“微调”我的批处理脚本(添加IF语句)

  1. 复制从位置.doc文件到另一个
  2. 在新的地点重新命名它(加入当前日期的名字)
  3. 打开其中的复制/重命名的文件现在位于
  4. 播放确认声音

的(初步)批处理脚本b中的位置依靠小型玩家(BP)播放声音的elow,可以很好地满足上述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"文件已经存在在那个位置,应该跳过xcopyren命令(但其余的应该继续)。上述

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

预先感谢你的帮助

回答

0

根据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

+0

@米莎:感谢您指出我正确的方向和你提供的链接(很好的提示)。 –

+0

感谢您的提示,我改进了我的脚本,如下所示:IF EXIST“D:\ My Documents \ New Word Document(%date%).doc”(goto PLACE)else goto OTHER PLACE ...通过这种方式,更快乐:D –