13

OSX I can do this:

someCommand -someOtherParameter ../../../../../ThisFileIsNeeded -yetAnotherParameter

When I try to do the same thing on Windows it yields:

"The system cannot find the file specified"

because the result path is something like:

c:\myFolder\otherFolder\IamHere\..\..\..\..\ThisFileIsNeeded

How can I write relative paths for windows cmd?

1 Answer 1

20

Relative paths

Paths, and relative ones, work very similar to what you have in OS X/macOS.

  • Windows uses "\", not "/".
  • Basically ".." is one level higher
  • ".\" is a sub-folder of the current working directory

Example

If you are located in c:\dev\repos\repo1 and you want to do something with a file located in c:\dev\bin\ (example below for PowerShell).

C:\dev\repos\repo1> Start-Process ..\..\bin\my_executable.exe

Command line above in words:

Start a process using the file my_executable.exe found (with starting point in the current directory (relative path)) by going two directories back up and then down in to directory bin.

Sub Folder Example If you are located in c:\dev\repos\repo1 and you want a sub-folder \My_Project\repo1.exe (example below for PowerShell).

C:\dev\repos\repo1> Start-Process .\My_Project\repo1.exe

It seems to me that you do know how relative paths work. Reply with exact commands so that I can reproduce what you're trying.

5
  • 1
    Start-Process isn’t exactly “cmd style”. :P // With tab autocomplete, working with relative paths is even easier, because you can “look into” the current directory level.
    – Daniel B
    Nov 21, 2017 at 22:31
  • I am not right now in my Pc but when I use it (although not direct in cmd.exe but in Vscode terminal) all the "\" just get deleted, so ..\bin\my_executable becomes c:\myPath\..binmyexecutable.exe
    – distante
    Nov 22, 2017 at 8:35
  • @DanielB Haha, true... :) Nov 22, 2017 at 9:46
  • @distante That means you’re encountering some bug. It definitely works the way described in this answer. Did you try with a “real” console window yet?
    – Daniel B
    Nov 22, 2017 at 14:57
  • Weird enough, after a reboot it all works.. even with ./../ (in vs code console an a "real console". I honestly do not know why this happend.
    – distante
    Nov 22, 2017 at 21:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .