Get the current working directory
From CodeCodex
Contents |
[edit] Implementations
[edit] C: POSIX
#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;
}
[edit] Haskell
import System.Directory(getCurrentDirectory) main = putStrLn =<< getCurrentDirectory
[edit] Java
The working directory is the location in the file system from where the java command was invoked.
String curDir = System.getProperty("user.dir");- Original Source: The Java Developers Almanac 1.4
[edit] Objective-C
NSString *curDir = [[NSFileManager defaultManager] currentDirectoryPath];
[edit] OCaml
let curDir = Sys.getcwd ()
[edit] Perl
use Cwd; my $curDir = getcwd;
[edit] PHP
$curDir = getcwd();
[edit] Python
import os curDir = os.getcwd()
[edit] Ruby
curDir = Dir.pwd
[edit] Zsh
print $PWD

