Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm writing a small batch file to replace users' themes and charts in Office. I have the below batch file that works just fine.

cd c:\documents and settings\%username%\application data\microsoft\templates
echo Y | rmdir charts /s
mkdir charts
echo Y | del "c:\documents and settings\%username%\application data\microsoft\templates\document themes\*.*"

net use o: \\servername\sms
copy "o:\ppt themes\charts\*.*" "c:\documents and settings\%username%\application data\microsoft\templates\charts"
copy "o:\ppt themes\Document Themes\*.*" "c:\documents and settings\%username%\application data\microsoft\templates\document themes"

c:
net use o: /delete

Now what I want is the above to only run if it hasn't run before as we'll be pushing this out to all users for around 2 weeks to catch people that aren't in every day.

Is there any way to begin the command with something to look for one of the new themes/charts already pushed down, and if it's present, then have it not run?

Any help on this would be greatly appreciated as I'm pretty new to these batch files.

share|improve this question
2  
A few unrelated comments: 1) rmdir /s/q somedirectory - no unneeded prompts; 2) you can copy directly out of \\servername\share\path\file, so net use is unnecessary. –  grawity May 14 '10 at 19:18
    
It's also possible to use the /q flag with the del command too. –  afrazier May 14 '10 at 20:10
    
@afrazier: Yes, but del will leave the empty subdirectories behind. –  grawity May 14 '10 at 20:37
    
Ah I tried to copy directly out of the server share and it threw up some error when I viewed it with Pause. I can't remember what the error was, though. I'll give it another shot, though, to try and tidy it up. Thanks =) –  Rossaluss May 14 '10 at 23:13
    
@grawity: I know, but the question has an echo Y | del C:\Path\* statement, so I thought the asker might find that tidbit useful. –  afrazier May 15 '10 at 0:27

1 Answer 1

if exist path\to\some\file\here goto end

.... the rest of your script here .... .... ....

:end

Note the colon preceding the label ('end', in this case) - it's important. The actual label word, 'end', isn't magic; any word (used on both places) would do.

share|improve this answer
1  
In cmd.exe you can use goto :eof instead, which doesn't need a label. –  grawity May 14 '10 at 19:15
    
This approach assumes some unique "version" file that you'd push out also. (Before and after the script runs, files exist in \charts and \document themes) –  RJFalconer May 14 '10 at 20:13
    
Thanks JRobert, I'll give that a shot when I'm back in on Monday. –  Rossaluss May 14 '10 at 23:14
    
RJFalconer: Of course just any old file wouldn't do; the presence of the file tested for needs to uniquely indicate that the update has taken place. –  JRobert May 15 '10 at 10:54
    
The files being pushed down will have unique names not present before the push, so that shouldn't be a problem. –  Rossaluss May 17 '10 at 7:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.