1

I have to:

  1. Copy a .doc file from a location to another
  2. Rename it at the new location (adding the current date to the name)
  3. Open the location where the copied/renamed file is now located
  4. Play a confirmation sound

The (rudimentary) batch script below that relies on a small player (BP) to play the sound, works nicely for the 4 above points.

@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

I would like to ask somebody who (unlike me) is familiar with scripts to help me to add some IF statements, namely:

  • Ref point 2 above: If the "New Word Document (%date%).doc" file already exists at that location, the xcopy and the ren commands should be skipped (but the rest should continue).

and

  • Ref point 3 above: If the folder "D:\My Documents\" is already open the start command should be skipped (but the rest should continue).

Thanks in advance for your kind help

Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
Eta Beta
  • 157
  • 1
  • 3
  • 11

1 Answers1

0

According to How to verify if a file exists in a Windows .BAT file? and 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"
)

For the second part you seem to be out of luck, according to "Bring to front" for Windows XP command shell

Community
  • 1
  • 1
Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
  • @ Micha: Thanks for pointing me in the right direction and for the links you provided (nice tips). – Eta Beta May 26 '13 at 10:18
  • Thanks to your tip I improved my script like this: IF EXIST "D:\My Documents\New Word Document (%date%).doc" (goto PLACE) else goto OTHER PLACE... In this way it makes me even happier :D – Eta Beta May 26 '13 at 11:16