Solved Batch file If Statement

February 20, 2013 at 09:30:44
Specs: Windows 7

I have a simple problem; I have a report that is housed in a directory tuesday through Thusday and in another directory on Monday and Friday. I want to create a batch file that opens the pdf report regardless of which directory the report is in. I can't get my if statment to work? Thoughts?

See More: Batch file If Statement

Report •


✔ Best Answer
February 20, 2013 at 16:14:07

No, all mine does, essentially is:
IF report.pdf is in tue_thu dir, THEN copy it to mon_fri dir ELSE do nothing
(that's the COPY part)
OPEN report.pdf which will now always be located in the mon_fri directory
(that's the START part, which should load acroread with your file in place if the association (PDF==acroread) is set up.)
Like i said at first, there's lots of ways to do this, so it shouldn't present a problem. M2's version is another way, and here's yet another:
if exist \xxx\tue_thu\report.pdf (start \xxx\tue_thu\report.pdf) else (start \xxx\mon_fri\report.pdf)

of course, "substitute the correct path and filenames" goes without saying but I said it anyway ;-)



#1
February 20, 2013 at 10:02:20

There are lots of ways, but to me the easiest is:
copy /y \t_th\x.pdf \m_f\x.pdf 2>nul
start \m_f\x.pdf


Report •

#2
February 20, 2013 at 10:05:32

Tkx nbrane, I will try to digest this; I have very little knowledge of batch scripting so it's all foreign to me. When I put the straight directory in where the report is the batch file works, but figuring out how to tell it look to the other directory has been a pain in the butt for me . . .

Report •

#3
February 20, 2013 at 10:14:12

Well, this just "tries" to copy the file to a single location. If the copy fails, the file did not need to be copied since it's already in the m_f, and "2>nul" simply suppresses the errormessage "file not found" when the file is not in t_th dir. Either way, the file winds up in M_F dir so you don't have to "search" or use conditionals.

Report •

Related Solutions

#4
February 20, 2013 at 10:18:53

Yeah, problem is Im having is I want the report to actually open via the batch
So if it's in directory A or B I want it to open despite which day of the week it is

Report •

#5
February 20, 2013 at 10:41:23

So I can get the code to work, but now it's always looking to... start \m_f\x.pdf
If I remove the file from the start directory it doesn't open the report from the other directory??

Report •

#6
February 20, 2013 at 10:46:24

Also, the report would never be in both directories at the same time:
Directory A: the report is available tues, Wed, Thurs
Directory B: the report is available Mon, Fri

Report •

#7
February 20, 2013 at 12:10:50

for /f "tokens=* delims= " %%a in ('dir/b/s c:\my.pdf') do (
start %%a
)

=====================
M2 Golden-Triangle


Report •

#8
February 20, 2013 at 12:54:24

Thanks Mechanix2Go, I have to chew on that one for a few to see how I can it to work to look at both directories...

Report •

#9
February 20, 2013 at 16:14:07
✔ Best Answer

No, all mine does, essentially is:
IF report.pdf is in tue_thu dir, THEN copy it to mon_fri dir ELSE do nothing
(that's the COPY part)
OPEN report.pdf which will now always be located in the mon_fri directory
(that's the START part, which should load acroread with your file in place if the association (PDF==acroread) is set up.)
Like i said at first, there's lots of ways to do this, so it shouldn't present a problem. M2's version is another way, and here's yet another:
if exist \xxx\tue_thu\report.pdf (start \xxx\tue_thu\report.pdf) else (start \xxx\mon_fri\report.pdf)

of course, "substitute the correct path and filenames" goes without saying but I said it anyway ;-)


Report •

#10
February 21, 2013 at 05:56:03

Tkx nbrane; I was waayyy over thinking it (smacks head)

Report •


Ask Question