chdir

chdir() to home directory

我是研究僧i 提交于 2019-11-30 22:00:00
问题 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 wrong? 回答1: Tilde expansion is handled by the shell, not by a system call. You could use getenv() to read the environment variable HOME and then use that as the argument to chdir() . There are system calls to get this information that may be more

chdir() not affecting environment variable PWD

冷暖自知 提交于 2019-11-29 14:44:15
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 ) { printf("Directory changed. The present working directory is \"%s\" \"%s\"\n",getenv("PWD"),getcwd(NULL,0)); } else { printf("Error changing dir %s\n",strerror(errno)); } } Output: (location of the executable is /home/user) changedir /boot Directory changed. The present working directory is "/home/user" "/boot" Yes, if you want to change the environment variable, you have

R: source() and path to source files

爱⌒轻易说出口 提交于 2019-11-29 10:00:25
问题 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 file containing some functions, functions.R . Both of these are in the same directory. If I call source('functions.R') inside the wrapper script, while standing inside the directory where both files are located, everything is fine. However, I want

Change directory in terminal using python

大憨熊 提交于 2019-11-29 07:05:21
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__ == '__main__': os.chdir("/home/name/projects/python") os.system("pwd") print 'dir changed' Output is: bash:~$ python chdir.py /home/name/projects/python dir changed bash:~$ pwd /home/name I want the directory change to remain even after the program has exited. Any ideas how to do it? Edit : What I really want to do is this: I use this directory frequently and

Change directory of parent process after exit [duplicate]

五迷三道 提交于 2019-11-28 14:11:52
Possible Duplicate: How do I set the working directory of the parent process? Is possible to make the change of directory persist after program exit? Since it resets to original directory when program exits. Jonathan Leffler A child process cannot affect its parent's current directory, any more than it can really affect its parent's environment . If the child removes the parent's current directory, it makes it so that the parent doesn't have a named current directory, but that's about all. No. Why do you wish that the directory changes? 来源: https://stackoverflow.com/questions/11806810/change

chdir() not affecting environment variable PWD

笑着哭i 提交于 2019-11-28 08:39:53
问题 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 ) { printf("Directory changed. The present working directory is \"%s\" \"%s\"\n",getenv("PWD"),getcwd(NULL,0)); } else { printf("Error changing dir %s\n",strerror(errno)); } } Output: (location of the executable is /home/user) changedir /boot Directory changed. The present

how to use chdir to change to current directory?

烈酒焚心 提交于 2019-11-28 04:15:07
问题 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 back to where file.php is located? or do I have to do it manually? 回答1: First you need to store the current path, before changing dirs: $oldPath = getcwd(); chdir('/some/path'); include(./file.php); chdir($oldPath); Why do you need to change dirs

Change directory in terminal using python

十年热恋 提交于 2019-11-28 00:30:07
问题 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__ == '__main__': os.chdir("/home/name/projects/python") os.system("pwd") print 'dir changed' Output is: bash:~$ python chdir.py /home/name/projects/python dir changed bash:~$ pwd /home/name I want the directory change to remain even after the program has exited

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

十年热恋 提交于 2019-11-27 16:45:13
问题 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 Runtime Environment (build 1.6.0_14-b08) Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing) Here's a test class I'm using: import java.io.*; public class Ch { public static void main(String[] args) { System.out.println(new File(".")

Change directory of parent process after exit [duplicate]

故事扮演 提交于 2019-11-27 08:21:19
问题 Possible Duplicate: How do I set the working directory of the parent process? Is possible to make the change of directory persist after program exit? Since it resets to original directory when program exits. 回答1: A child process cannot affect its parent's current directory, any more than it can really affect its parent's environment. If the child removes the parent's current directory, it makes it so that the parent doesn't have a named current directory, but that's about all. 回答2: No. Why do