Get the current working directory

From CodeCodex

Implementations[edit]

C: POSIX[edit]

#include <unistd.h>
#include <stdio.h>
#define BUF_SIZE 40

int main() {
    char buf[BUF_SIZE];
    char *curDir = getcwd(buf, BUF_SIZE);
    if (curDir)
        puts(curDir);
    return 0;
}

Erlang[edit]

Cwd = file:get_cwd().

Haskell[edit]

import System.Directory(getCurrentDirectory)
main = putStrLn =<< getCurrentDirectory

Java[edit]

The working directory is the location in the file system from where the java command was invoked.

String curDir = System.getProperty("user.dir");

Objective-C[edit]

NSString *curDir = [[NSFileManager defaultManager] currentDirectoryPath];

OCaml[edit]

let curDir = Sys.getcwd ()

Perl[edit]

use Cwd;
my $curDir = getcwd;

PHP[edit]

$curDir = getcwd();

Python[edit]

import os
curDir = os.getcwd()

Ruby[edit]

curDir = Dir.pwd

Tcl[edit]

set curdir [pwd]

Zsh[edit]

print $PWD