Questions tagged [getcwd]

The getcwd() function retrieves the current working directory pathname on POSIX compliant machines.

The function getcwd() is available on Unix machines to copy the current working directory (as an absolute pathname) to a supplied buffer of an array of characters of a given length. It is specified in POSIX.1-2001 to have the following signature:

char *getcwd(char *buffer, size_t size);
88 questions
565
votes
12 answers

How can I find script's directory?

Consider the following Python code: import os print os.getcwd() I use os.getcwd() to get the script file's directory location. When I run the script from the command line it gives me the correct path whereas when I run it from a script run by code…
Jonathan
  • 84,911
  • 94
  • 244
  • 345
242
votes
9 answers

sh: 0: getcwd() failed: No such file or directory on cited drive

I am trying to compile ARM code in Ubuntu 12. Everything is working fine when I put the code in the local directory. But when I put the code in cited mount directory error shows up: making testXmlFiles sh: 0: getcwd() failed: No such file or…
CrazyKitty Rotoshi
  • 2,429
  • 2
  • 11
  • 4
158
votes
4 answers

shell init issue when click tab, what's wrong with getcwd?

once i click Tab on bash, the error message will appear, what's wrong? symlink-hook: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory symlink-hook: error retrieving current directory: getcwd:…
hugemeow
  • 7,177
  • 13
  • 43
  • 59
40
votes
8 answers

Is there a C++ equivalent to getcwd?

I see C's getcwd via: man 3 cwd I suspect C++ has a similar one, that could return me a std::string . If so, what is it called, and where can I find it's documentation? Thanks!
anon
  • 36,629
  • 47
  • 184
  • 286
36
votes
3 answers

get script directory name - Python

I know I can use this to get the full file path os.path.dirname(os.path.realpath(__file__)) But I want just the name of the folder, my scrip is in. SO if I have my_script.py and it is located at /home/user/test/my_script.py I want to return "test"…
spen123
  • 2,934
  • 10
  • 34
  • 50
23
votes
3 answers

PHP: How to set current working directory to be same as directory executing the script

I'm in the process of transferring my website from one server to another. I have some php scripts that use the is_readable function which uses the current working directory. On the old server, when I call getcwd(), it outputs the folder in which…
MF86
  • 255
  • 1
  • 3
  • 8
20
votes
3 answers

What is a cross-platform way to get the current directory?

I need a cross-platform way to get the current working directory (yes, getcwd does what I want). I thought this might do the trick: #ifdef _WIN32 #include #define getcwd _getcwd // stupid MSFT "deprecation" warning #elif …
rubenvb
  • 69,525
  • 30
  • 173
  • 306
17
votes
5 answers

get current working directory in Lua

What's the Lua to get the current working directory on Windows XP SP3 (or to get the directory of the currently-running Lua file)? I prefer not to use LuaFileSystem. I can't use os.execute("cd") because os.execute always starts from my home…
user600838
12
votes
1 answer

How do Perl Cwd::cwd and Cwd::getcwd functions differ?

The question What is the difference between Cwd::cwd and Cwd::getcwd in Perl, generally, without regard to any specific platform? Why does Perl have both? What is the intended use, which one should I use in which scenarios? (Example use cases will…
Palec
  • 10,298
  • 7
  • 52
  • 116
12
votes
2 answers

Launching a python script via a symbolic link

I have an executable python script that exists in a "scripts" directory, and there's a symbolic link to that script (used to launch the file) in a root directory. Something like: . ├── scripts │ ├── const.py │ ├── fops.py │ ├── i_build.py │ …
Mike
  • 40,613
  • 26
  • 100
  • 171
11
votes
1 answer

php getcwd() resolving target of symlink instead of current directory

As far as I am aware, php's getcwd() (and similar functions eg dirname(__FILE__)) are supposed to return the current directory of the file being executed. If the current directory happens to be a symlink to another directory, php (presumably in…
myk00
  • 299
  • 1
  • 3
  • 8
7
votes
3 answers

Changing to a directory and then getcwd()

Many of my colleagues use the following commands in their BEGIN block. $scriptDir = dirname($0); chdir($scriptDir); $scriptDir = getcwd(); I have looked around and can't help but think that the third line i.e. $scriptDir = getcwd(); is redundant.…
tarunkt
  • 186
  • 12
6
votes
3 answers

vscode working directory when debugging python

I have a simple problem regarding debugging python script on vscode . When I open a parent directory on vs code that contains multiple children directories and then I open multiple python files from these children directories. I then try to debug…
stackunderflow
  • 3,539
  • 4
  • 24
  • 38
5
votes
2 answers

Why is iget() hidden in xv6

I'm playing a bit with xv6, a modern implementation of Unix version 6. For my first hack, I wanted to implement the simple getcwd syscall, but I'm a bit lost as to which level of abstraction I should use. Should I use the struct file interface? Or…
NewbiZ
  • 2,218
  • 1
  • 24
  • 31
5
votes
2 answers

Why does getcwd() returns / in __destruct()?

I have just noticed that getcwd() return "/" if called within __destruct() magic function, while in any other method it returns the expected path. Do you have an explanation for this?
Michael
  • 4,376
  • 10
  • 42
  • 66
1
2 3 4 5 6