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);
104 questions
664
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 Livni
  • 101,334
  • 104
  • 266
  • 359
295
votes
8 answers

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

I am trying to compile ARM code on Ubuntu 12.04 (Precise Pangolin). Everything is working fine when I put the code in the local directory. But when I put the code in the cited mount directory, an error shows up: making testXmlFiles sh: 0: getcwd()…
CrazyKitty Rotoshi
  • 2,959
  • 2
  • 13
  • 4
160
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,777
  • 13
  • 50
  • 63
47
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
  • 41,035
  • 53
  • 197
  • 293
38
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
  • 3,464
  • 11
  • 39
  • 52
25
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
  • 275
  • 1
  • 4
  • 8
24
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
  • 74,642
  • 33
  • 187
  • 332
22
votes
6 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
14
votes
3 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
  • 47,263
  • 29
  • 113
  • 177
12
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
  • 329
  • 1
  • 3
  • 10
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
  • 12,743
  • 8
  • 69
  • 138
9
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,811
  • 5
  • 31
  • 43
8
votes
3 answers

Find path of python_notebook.ipynb when running it with Google Colab

I want to find the cwd where my CODE file is stored. With jupiter Lab i would do: import os cwd= os.getcwd() print (cwd) OUT: 'C:...\\Jupiter_lab_notebooks\\CODE' However,if i copy the folders to my GoogleDrive, and run the notebook in GOOGLE…
Leo
  • 1,176
  • 1
  • 13
  • 33
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
  • 306
  • 2
  • 12
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,395
  • 2
  • 26
  • 40
1
2 3 4 5 6 7