This language bar is your friend. Select your favorite languages!

Idiom #106 Get program working directory

Assign to string dir the path of the working directory.
(This is not necessarily the folder containing the executable itself)

$dir = getcwd();
with Ada.Directories; use Ada.Directories;
Dir : String := Current_Directory;
import std.path;
string dir = absolutePath;
import "os"
dir, err := os.Getwd()
import System.Directory
dir <- getCurrentDirectory
String path = this.getClass().getClassLoader().getResource("").getPath();
dir := expandfilename('.');
use Cwd;
my $dir = getcwd();
import os
dir = os.getcwd()
dir = Dir.pwd

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms