Questions tagged [chdir]

chdir (or cd) is a command to change the working directory (change directory). It is part of many operating systems and programming languages. On many OS `chdir()` also is a system call.

cd, sometimes also available as chdir (change directory), is a command line command to change the current working directory in operating systems such as Unix, DOS, OS/2, AmigaOS (where if a bare path is given, cd is implied), Windows, and Linux. It is also available for use in shell scripts and batch files.

More details see cd Wikipedia article

202 questions
1
vote
2 answers

C — using chdir() function

I'm trying to use chdir() function but can't work it out. I'm reading from user and find out if he is using "cd". I always get an error. What am I doing wrong? Code: int * status=0; char * buf = 0; char arguments[2048]; buf =…
Aviram Fireberger
  • 3,910
  • 5
  • 50
  • 69
1
vote
2 answers

Linux daemon: alternative to chdir("/")?

I have a program (Crafty chess) that works just fine when started from the console. For my application I have daemonized it. When daemonizing a process, one is supposed to change the working directory to "/" via chdir("/"). When I follow that…
chessweb
  • 4,613
  • 5
  • 27
  • 32
0
votes
1 answer

unistd.h's chdir gives undefined reference to symbol 'chdir@@GLIBC_2.2.5' on linux

When linking some object files together using ld, an error occurs: undefined reference to symbol 'chdir@@GLIBC_2.2.5' undefined reference to symbol 'setlocale@@GLIBC_2.2.5' Do I need to link a library for this function? The manpage does not say…
user21412139
0
votes
1 answer

Execve cd /bin pwd [C]

I am currently writing a shell in C (school project). My cd and pwd is working. But when I do: cd /bin and after pwd, pwd shows /usr/bin. For me it looks like execve with pwd can't handle /bin but why? name% ./myshell name: cd Current working dir:…
niki
  • 23
  • 7
0
votes
1 answer

Using chdir() to read all csv files in a directory

Here is an example of my directory: Auto ├── Test │ └── Test.csv ├── Test2 │ └── Test2.csv └── new.csv I am trying to read all the csv files in the directory. Here is my code: import glob, os os.chdir('C:\\Users\\Me\\Desktop\\Auto') for file…
GooseCake
  • 33
  • 8
0
votes
0 answers

How can I change directory in C without resolving symlinks?

I'm trying to create a C program that emulates a Bash shell. For the cd file instruction I use chdir("file") but it isn't correct because chdir() always resolves symlinks while cd doesn't by default. I'm looking for a way to get a function that…
babaoreum
  • 23
  • 5
0
votes
0 answers

can't attach file path on Python using Datalore

I am having difficulty extracting data from a file using os.chdir, I am using Datalore. But I get a similar error on VSCode, Jupiter Notebook as well. import numpy as np import matplotlib.pyplot as plt %matplotlib inline import…
devnewdevv
  • 23
  • 5
0
votes
0 answers

.. in file path, python os.chdir

I have encountered something, I am building a command line tool in python. Now I use the os.chdir to change the current working directory (with command cd). I noticed that when I put .. in the input, it brings me back in the directory tree. For…
nat34
  • 3
  • 5
0
votes
1 answer

Isolate state change of chdir within python exec scope

Running a script with exec, how does one "backup" python process global state in its entirety and restores it afterwards? code example: import os print(os.getcwd()) a = 8 print(a) exec_scope = {} exec(""" import os os.chdir('../new place') a =…
AturSams
  • 7,568
  • 18
  • 64
  • 98
0
votes
2 answers

The phpseclib $sftp->chdir('//ARTDONE.G9876TT1') fails on z/OS sftp server. The windows psftp command line of "CD //ARTDONE.G9876TT1" works

I get a valid connection with phpseclib but because of the server's requirements I must issue a change remote directory command, $sftp->chdir($dir="//ARTDONE.G9876TT1"), to this directory, (exact format, not the actual name). This change directory…
0
votes
2 answers

os.chdir returns No such file or directory: 'None'

How come that these lines of code creates a folder, but returns an error output? key_ = "Test" new_folder = os.makedirs(str(key_)+str(datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M'))) os.chdir(str(new_folder)) The error I'm getting…
AnxiousDino
  • 187
  • 15
0
votes
1 answer

Changing file path and need for raw?

import os cwd = os.getcwd() print("Current working directory: {0}".format(cwd)) # Print the type of the returned object print("os.getcwd() returns an object of type:…
abcdefg
  • 1
  • 3
0
votes
0 answers

Get the directory holding the file that I am currently executing

I have a file main.py stored in ~/project1/code/. In main.py, I have changed the working directory to import some other .py files: import os os.chdir('~/project2/code/') Afterwards, I want to point the working directory to the location where…
Emil
  • 1,531
  • 3
  • 22
  • 47
0
votes
1 answer

Traversing a file-system directory structure

I am trying to do some work within some files in a directory. The basic structure of what I'm trying to work with is folder -> sub-folders -> files I need to access. data holds hundreds of subfolders, I am trying to access each one, find the file…
WeekendJedi
  • 67
  • 10
0
votes
1 answer

cwd back to the original path

I am making my own shell using C-language. In the initial stage my cwd is say "/Users/Henry/test". One of the feature is that when i open a file the shell should not search for the file in the current working folder (cwd). Instead it should search…
henryD
  • 21
  • 3