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
4
votes
2 answers

What can I do if getcwd() and getenv("PWD") don't match?

I have a build system tool that is using getcwd() to get the current working directory. That's great, except that sometimes people have spaces in their paths, which isn't supported by the build system. You'd think that you could just make a…
Carl Norum
  • 201,810
  • 27
  • 390
  • 454
4
votes
2 answers

C programming getcwd variable manipulation

Basically I need an if statement of which the response is dependent upon the current working directory. I have done some research on the topic and I believe that the getcwd() function is what I am looking for, but I can't figure out how to interface…
user4493605
  • 371
  • 1
  • 15
4
votes
5 answers

Does the order I declare pointers really matter in C? getcwd() problem

On a Solaris 5.8 machine, I have the following code: [non-working code] char *buf; char *dir; size_t psize; psize = (size_t) 1024; dir = getcwd(buf, psize); On this unix machine, the above does not work and I get a segmentation fault when trying…
chucknelson
  • 2,260
  • 3
  • 24
  • 30
4
votes
4 answers

Python os.getcwd() returns with tilde in the path. e.g. C:\MYFOLD~1\test

How can I get python to return the full pathname of C:\myfolderisafolder\test?
Brad Conyers
  • 811
  • 4
  • 14
  • 21
3
votes
0 answers

What is the cause of the hard limit on the directory nesting depth returned by getcwd on macOS and how can it be circumvented?

On linux and macOS, directories can be nested to seemingly arbitrary depth, as demonstrated by the following C program. However, on macOS but not on linux, there seems to be a hard limit on the nesting level returned by getcwd, specifically a…
feeley
  • 61
  • 4
3
votes
7 answers

How return a std::string from C's "getcwd" function

Sorry to keep hammering on this, but I'm trying to learn :). Is this any good? And yes, I care about memory leaks. I can't find a decent way of preallocating the char*, because there simply seems to be no cross-platform way. const string getcwd() { …
rubenvb
  • 69,525
  • 30
  • 173
  • 306
3
votes
2 answers

Why doesn't 'C:' mean what I think it means?

On Windows 7 I fire up my IDLE Python 2.7.5 Shell: >>> import os >>> os.getcwd() 'C:\\Python27' >>> os.path.relpath('C:\\') '..' >>> os.path.relpath('C:') '.' >>> os.chdir('C:') >>> os.getcwd() 'C:\\Python27' What is going on, and why does it have…
Scruffy
  • 838
  • 1
  • 6
  • 20
3
votes
1 answer

Is there a wchar_t version of getcwd?

I am trying to this: wchar_t buff[PATH_MAX]; wgetcwd( buff, PATH_MAX); I have also tried _wgetcwd. Google suggests _wgetcwd is in dir.h, but i have never heard of such a header file. I'm using GCC 4.3. Thank you.
mikbal
  • 1,038
  • 1
  • 14
  • 26
2
votes
2 answers

getcwd second parameter

What should i fill in the second parameter of the function getcwd if I am reading the current directory?
lital maatuk
  • 5,345
  • 17
  • 53
  • 74
2
votes
0 answers

Shell Init Error trying to install Webpack

I am trying to install Webpack on OSX Sierra. I used the Sudo command and this is what I am getting shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied path.js:1142 cwd =…
2
votes
1 answer

Problems with getcwd syscall on OSX

Does anyone have an idea how to get the current working directory in OSX with NASM? The syscall getcwd isn't available on osx and dtruss pwd return lots of stat sys calls. However in the manual I can't find which structure variable of stat returns…
Agguro
  • 339
  • 2
  • 11
2
votes
0 answers

Docker: getcwd: cannot access parent directories

I have a Java app, packaged to the docker container via sbt-native-packager. When testing on local machine or other server, the container starts just fine. And on one of the CoreOS machines on Azure, I'm getting: shell-init: error retrieving current…
2
votes
1 answer

Return file directories in an array

I`m trying to create a function that reads a directory and returns all file's working directories in an array, but it is not working. I don`t know why the code doesn`t work, can you help me? $postsDirectory = "../posts/"; function listFiles() { …
1
vote
0 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…
David 8
  • 810
  • 4
  • 16
1
vote
3 answers

How to write dataframe to csv to the current working directory python

My code would be something like this: import os import pandas as pd cwd = os.getcwd() csv_name = '/CONTCAR_SORTED' df = pd.read_csv(f"{cwd}{csv_name}", skiprows=2, nrows=100, names=['X','Y','Z' ], …
J.Doe
  • 89
  • 7