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

182 questions
18
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
  • 18,334
  • 56
  • 153
  • 244
11
votes
4 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
  • 3,089
  • 7
  • 22
  • 36
11
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
  • 532
  • 1
  • 6
  • 21
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,378
  • 3
  • 14
  • 21
10
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
  • 1,717
  • 5
  • 31
  • 52
9
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
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
  • 2,685
  • 9
  • 26
  • 44
8
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
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
  • 85,654
  • 109
  • 315
  • 497
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,377
  • 9
  • 36
  • 52
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

chdir() - no such file or directory

int main(int argc, char **argv) { char input[150]; char change[2] = "cd"; char *directory; while(1) { prompt(); fgets(input, 150, stdin); if(strncmp(change, input, 2) == 0) { directory = strtok(input, " "); …
csczigiol
  • 73
  • 1
  • 5
5
votes
1 answer

Can chdir() accept relative paths?

In C on linux, can the chdir() function accept a relative path?
John Moffitt
  • 5,373
  • 7
  • 26
  • 39
5
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
  • 65
  • 1
  • 4
1
2 3
12 13