0

In Batch, I know you can always specify a folder path in batch/cmd, for example,

echo %RANDOM% >> C:\Users\User\Logs\log.txt

or

start C:\Windows\System32\cmd.exe

But what if for example, your batch file was used in a product, where these locations may differ or not exist? How would you specify?

Dorian Dore
  • 742
  • 3
  • 13
  • 30
  • possible duplicate of [How to verify if a file exists in a Windows .BAT file?](http://stackoverflow.com/questions/3022176/how-to-verify-if-a-file-exists-in-a-windows-bat-file) – Ali Sepehri.Kh Nov 15 '14 at 06:13
  • I suspect you may want `%~dp0` - the path to the batch file that is currently executing. – dbenham Nov 15 '14 at 22:04
  • 1
    There are variables (often referred to as "environment variables") that Windows creates to help you find certain things. You can see a list of them by type `set` at a cmd prompt. So if you want to launch a program from the windows directory, but you aren't sure that windows directory is "c:\windows", you can use `start %windir%\system32\cmd.exe`. Similarly, there is USERPROFILE, so you can do echo %random% > %USERPROFILE%\logs\log.txt. – David Wohlferd Nov 19 '14 at 08:27

1 Answers1

0
if exist filename.ext (
    rem file exists
) else (
    rem file doesn't exist
)

Please also see this question.

If that is not possible to use relative path, use environment variables; because every thing can be different in your client station.

Community
  • 1
  • 1
Ali Sepehri.Kh
  • 2,350
  • 2
  • 15
  • 25