Difference between revisions of "Get the current working directory"

From CodeCodex

(Erlang)
(Implementations)
 
Line 63: Line 63:
 
<pre class="ruby">
 
<pre class="ruby">
 
curDir = Dir.pwd
 
curDir = Dir.pwd
 +
</pre>
 +
 +
=== Tcl ===
 +
<pre class="tcl">
 +
set curdir [pwd]
 
</pre>
 
</pre>
  
Line 80: Line 85:
 
[[Category:Python]]
 
[[Category:Python]]
 
[[Category:Ruby]]
 
[[Category:Ruby]]
 +
[[Category:Tcl]]
 
[[Category:Zsh]]
 
[[Category:Zsh]]
 
[[Category:I/O]]
 
[[Category:I/O]]

Latest revision as of 20:13, 1 March 2011

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