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

Why some functions return the result both in return value and by writing to pointer passed?

Recently was reading man page of getcwd(3). It writes current working directory to passed buf pointer and also returns it as pointer to char. Could you please explain why it does so(giving result using two ways)?
Bulat M.
  • 680
  • 9
  • 25
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
  • 348
  • 3
  • 11
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
3 answers

What is the console equivalent of clicking on a command in a markdown file in PyCharm?

I have a folder with a README.md and a run.py that looks like this: import os assert __name__ == '__main__' print('■', __file__) print('●', os.getcwd()) try: os.mkdir('DELETE_ME') except FileExistsError: pass The readme contains the…
Watchduck
  • 1,076
  • 1
  • 9
  • 29
1
vote
1 answer

How to get the current path with symlink (not the actual path) in a c program on a linux system?

I am currently building a custom shell that can handle a few internal and external commands along with their options. One of these internal commands is pwd. From the man page of pwd, I got that pwd -L is going to output the current working directory…
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
  • 109
  • 1
  • 1
  • 8
1
vote
1 answer

is there such thing as a getcwd() syscall on macos

I am wondering if there is a getcwd system call on macos. I can't seem to find any leads on the code for getcwd apart from https://www.informatik.htw-dresden.de/~beck/ASM/syscall_list.html. However, the code it gives does not function. I have tried…
1
vote
1 answer

Python: os.getcwd() randomly fails in mounted network drive

I'm on Debian using python3.7. I have a network drive that I typically mount to /media/N_drive with dir_mode=0777 and file_mode=0777. I generally have no issues with reading/writing files in this network drive. Occasionally, especially soon after…
1
vote
5 answers

warning: comparison between pointer and integer in C

I get a warning warning: comparison between pointer and integer on the line containing if from the next piece of code: char cwd[1024]; if (getcwd(cwd, sizeof(cwd)) != (char*)NULL) printf("%s\n",cwd); else error_print("error in pwd"); how…
SIMEL
  • 8,745
  • 28
  • 84
  • 130
1
vote
1 answer

getcwd error when $HOME

I wrote my own find() function. When I do: ./myown $HOME/Documents test.txt I get: /Users/CJ/Documents/test/test.txt /Users/CJ/Documents/test/test1/test.txt /Users/CJ/Documents/test/test2/test.txt However when I do: ./myown $HOME test.txt I…
C.J
  • 169
  • 1
  • 12
1
vote
1 answer

Change current working directory in child process in C

I have to write a program which generates child process than ends parent process and after that that created child process has to ask user to input new working directory, change it and print path to its new working directory. I wrote this, but scanf…
Sz3jdii
  • 507
  • 8
  • 23
1
vote
2 answers

Python module import not working

I am getting an error with the following code: from os import getcwd os.getcwd() Traceback (most recent call last): File "", line 1, in os.getcwd() NameError: name 'os' is not defined Anyone know why importing this way is not…
West
  • 2,350
  • 5
  • 31
  • 67
1
vote
2 answers

current working directory mismatch in python

I have imported a existing filesystem folder as the new project folder in eclipse. I have a script which get the current working directory path of the code. I need to change directory location to acccess files in other directory related to it. But…
1
vote
2 answers

Why getcwd fails with errno ENOENT

I'm using the getcwd function to retrieve the current working directory of my application. In some cases it fails and errno is ENOENT. I call getcwd from different threads, but serially and sometimes I face with ENOENT, but I don't know why. The…
rboc
  • 344
  • 3
  • 10
1
vote
1 answer

pycharm os.listdir does not list contents

I am a SO virgin. Treat me gently. In Python3.5 I can run: import os os.listdir('C:/Users/Tim0t_000/Desktop/python automate boring downloads') and this produces the list of files contained in that directory. If I run the same script in Pycharm, it…
Tim0th1
  • 65
  • 8