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.

Hello I have the following batch file saved to a location called C:\.alias. I added this directory to the path so that I can run all my custom scripts. I have tried creating a script to open a file in Chrome. When I am in another directory e.g. C:\code\python I call my script: chrome.cmd text.svg but Chrome tries to open: file:///C:/.alias/test.svg. Is there a way to prepend current path to the filename argument? Thanks.

chrome.cmd

@echo off
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" %~dp0%1
share|improve this question

1 Answer 1

up vote 2 down vote accepted

%~dp0 is the path to the location of the batch file.

%cd% is the current working directory.

This is what you need:

@echo off
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" %cd%\%1
share|improve this answer
    
Thanks! I added the path delimiter to your answer. –  Mr. Polywhirl Jan 24 '13 at 4:43
1  
So I see. I was testing from C:\ , and when that is the working directory, %cd% includes the trailing \ . –  William Jackson Jan 24 '13 at 4:45

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.