Home » Questions » Computers [ Ask a new question ]

Get Batch file to run relative to actual folder, not shortcut

Get Batch file to run relative to actual folder, not shortcut

I've created a few batch files that moves files around relative to the folder the batch file is in.

Asked by: Guest | Views: 30
Total answers/comments: 1
Guest [Entry]

"Put the following at the top of your batch file:

CD /D %~dp0

Explanation:

The /D option tells CD to change current drive as well as current directory for a drive.
%0 is the name of the batch file
The ~ says we want to use some modifiers
d expands to drive letter.
p expands to a path.

So %~dp0 is the directory in which the batch file resides."