Reputation: 41
I am writing a startup script to open a .pdf file. When I execute the command in cmd window, the .pdf will open just fine, but when I execute the command from a .bat file, it says "Windows cannot find 'myfilename.pdf'. Make sure you typed the name correctly, and then try again." The command I am using is
start myfilename.pdf C:\Temp
Not really sure what I should change other than perhaps insert change directory to C:\Temp before executing the start command?
Upvotes: 0
Views: 587
Reputation: 163
When you run your command from the command line I assume you are in the same directory as the pdf file. That is why the file is found. When you run a .bat file, the starting path is the path of the .bat file. If you have the .bat file in the same directory as the .pdf file, your command will work. If you have the .bat file in a different directory you can first change the current directory to the one that contains the .pdf file, or give the full path to the file like below:
start C:\LocationOfPdfFile\myfilename.pdf C:\Temp
Upvotes: 1
Reputation: 4658
If your batch file is not in the same directory as your file, it cannot be opened. If you specify the path it does not matter in what directory you are.
if exist C:\Temp\myfilename.pdf (
rem file exist an is being opened
start C:\Temp\myfilename.pdf
) else (
rem file doesn't exist
)
Upvotes: 0