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

chdir() to home directory

I am using the chdir() C function to allow a user to change directory. The function however, doesn't recognize '~'. Do I need to do any explicit conversion, so chdir doesn't recognize what ~ means? Because mine isn't working. Or am I doing something…
darksky
  • 20,411
  • 61
  • 165
  • 254
18
votes
5 answers

R: source() and path to source files

There must be something that I don't understand about the source() command in R. I'm still new to it, but I cannot for the life of me understand how it gets its directories from! My problem is this: I have a wrapper script, wrapper.R, and a source…
erikfas
  • 4,357
  • 7
  • 28
  • 36
16
votes
3 answers

Change directory in terminal using python

I'm writing a simple script to change the present working directory to some other directory. The following script works okay until the program terminates, after which I'm back to my home directory. #!/usr/bin/python import os if __name__ ==…
Krishh
  • 602
  • 1
  • 8
  • 25
11
votes
2 answers

Difference between cd and function chdir

What is the difference between the cd shell command and the Perl function chdir? Please can you explain with an example?
iDev
  • 2,163
  • 10
  • 39
  • 64
10
votes
4 answers

source code for unix environments 'cd' command

Where can I find the source code for Unix environment's cd command? I want to know how the command is implemented.
debugger
10
votes
5 answers

Python os.chdir is modifying the passed directory name

I am trying to change the current working directory in python using os.chdir. I have the following code: import os os.chdir("C:\Users\Josh\Desktop\20130216") However, when I run it, it seems to change the directory, as it comes out with the…
Josh Wood
  • 1,598
  • 3
  • 16
  • 21
9
votes
2 answers

Why setlocal interferes with chdir in windows batch files?

If I run the batch file setlocal chdir .. the directory is not changed, but if I run setlocal endlocal chdir .. it works normally. This must be exactly what is expected with setlocal. However, it is not entirely obvious when you read the…
user2066805
9
votes
3 answers

How can I change drives using python os?

I'm trying to change the current directory from C: to Y: I tried: import os os.chdir('Y:') but I keep getting an error saying that it can't locate the drive. Essentially I'm looking for the equivalent of the cd /d command in cmd.
aensm
  • 3,325
  • 9
  • 34
  • 44
7
votes
3 answers

Why is the user.dir system property working in Java?

Almost every article I read told me that you can't have chdir in Java. The accepted answer to this question says you can't do it in Java. However, here's some of the stuff I tried: geo@codebox:~$ java -version java version "1.6.0_14" Java(TM) SE…
Geo
  • 93,257
  • 117
  • 344
  • 520
6
votes
1 answer

python os.path.realpath not working properly

I have following code: os.chdir(os.path.dirname(os.path.realpath(__file__)) + "/../test") path.append(os.getcwd()) os.chdir(os.path.dirname(os.path.realpath(__file__))) Which should add /../test to python path, and it does so, and it all runs…
jj.
  • 105
  • 1
  • 1
  • 5
6
votes
3 answers

how to use chdir to change to current directory?

I'm trying to include a file from another directory and then change the chdir back to the current/original form. chdir('/some/path'); include(./file.php); chdir();//How to I change the directory back to the original form? Anyway to change the chdir…
user962449
  • 3,743
  • 9
  • 38
  • 53
6
votes
1 answer

os.chdir() to relative home directory (/home/usr/)

Is there a way to use os.chdir() to go to relative user folder? I'm making a bash and the only issue I found is the cd ~, arg[0] is undefined since I'm using this cd functions: def cd(args): os.chdir(args[0]) return current_status Which I…
Seraf
  • 850
  • 1
  • 17
  • 34
6
votes
3 answers

chdir() not affecting environment variable PWD

When I use chdir() to change the current working directory, why doesn't the getenv("PWD") give the present working directory? Do I need to setenv("PWD",newDir,1) also? void intChangeDir(char *newDir) { if( chdir(newDir)==0 ) { …
user191776
6
votes
1 answer

source(..., chdir=TRUE) does not seem to change the directory

I'm pretty new to R and I'm trying to source a file which is again sourcing files. So I have a file, lets call it mother.R which contains a source call: source ("grandmother.R") mother.R and grandmother.R are in the same directory. I would now like…
chuelibrueder
  • 85
  • 1
  • 4
6
votes
1 answer

Changing directory in a pthread

My question is : How can i change the current directory in a pthread without changing the current directory in other pthreads, I found a solution which is using openat() function, but i didn't found any example explaining how it works. Using chdir()…
badr assa
  • 105
  • 1
  • 1
  • 6
1
2 3
13 14