working-directory

Change the current working directory in C++

て烟熏妆下的殇ゞ 提交于 2019-11-26 09:38:50
问题 How can I change my current working directory in C++ in a platform-agnostic way? I found the direct.h header file, which is Windows compatible, and the unistd.h , which is UNIX/POSIX compatible. 回答1: The chdir function works on both POSIX (manpage) and Windows (called _chdir there but an alias chdir exists). Both implementations return zero on success and -1 on error. As you can see in the manpage, more distinguished errno values are possible in the POSIX variant, but that shouldn't really

R command for setting working directory to source file location in Rstudio

旧城冷巷雨未停 提交于 2019-11-26 07:56:56
问题 I am working out some tutorials in R. Each R code is contained in a specific folder. There are data files and other files in there. I want to open the .r file and source it such that I do not have to change the working directory in Rstudio as shown below: Is there a way to specify my working directory automatically in R. 回答1: To get the location of a script being sourced, you can use utils::getSrcDirectory or utils::getSrcFilename . So changing the working directory to that of the current

changing the working-directory of command from java

∥☆過路亽.° 提交于 2019-11-26 07:46:47
问题 I need to execute a .exe file from a function in one of the packages I have in my java project. now the working directory is the root directory of the project for java but the .exe file in sub-directories of my project. here is how the project is organized: ROOT_DIR |.......->com | |......->somepackage | |.........->callerClass.java | |.......->resource |........->external.exe Initially I tried to run the .exe file directly through: String command = \"resources\\\\external.exe -i input -o

Get current batchfile directory

穿精又带淫゛_ 提交于 2019-11-26 06:55:10
问题 Firstly, I saw this topic but I couldn\'t understand that. Question : There is a batch file in D:\\path\\to\\file.bat with following content : echo %cd% pause Output is : C:\\ It must be D:\\path\\to What am I doing wrong? 回答1: System read-only variable %CD% keeps the path of the caller of the batch, not the batch file location. You can get the name of the batch script itself as typed by the user with %0 (e.g. scripts\mybatch.bat ). Parameter extensions can be applied to this so %~dp0 will

How to get the current directory in a C program?

て烟熏妆下的殇ゞ 提交于 2019-11-26 06:48:17
I'm making a C program where I need to get the directory that the program is started from. This program is written for UNIX computers. I've been looking at opendir() and telldir() , but telldir() returns a off_t (long int) , so it really doesn't help me. How can I get the current path in a string (char array)? Mic Have you had a look at getcwd() ? #include <unistd.h> char *getcwd(char *buf, size_t size); Simple example: #include <unistd.h> #include <stdio.h> #include <limits.h> int main() { char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd)) != NULL) { printf("Current working dir: %s\n", cwd); }

How to get current working directory in Java?

▼魔方 西西 提交于 2019-11-26 05:19:01
问题 Let\'s say I have my main class in C:\\Users\\Justian\\Documents\\ . How can I get my program to show that it\'s in C:\\Users\\Justian\\Documents ? Hard-Coding is not an option- it needs to be adaptable if it\'s moved to another location. I want to dump a bunch of CSV files in a folder, have the program recognize all the files, then load the data and manipulate them. I really just want to know how to navigate to that folder. 回答1: One way would be to use the system property System.getProperty(

How to find the working folder of a servlet based application in order to load resources

核能气质少年 提交于 2019-11-26 03:36:22
问题 I write a Java servlet that I want to install on many instances of Tomcat on different servers. The servlet uses some static files that are packed with the war file under WEB-INF. This is the directory structure in a typical installation: - tomcat -- webapps --- myapp ---- index.html ---- WEB-INF ----- web.xml ----- classes ------ src ------- ..... ----- MY_STATIC_FOLDER ------ file1 ------ file2 ------ file3 How can I know the absolute path of MY_STATIC_FOLDER, so that I can read the static

How to set the current working directory? [duplicate]

此生再无相见时 提交于 2019-11-26 02:39:41
问题 This question already has answers here : How do I change directory (cd) in Python? (12 answers) Closed last year . How to set the current working directory in Python? 回答1: Try os.chdir os.chdir(path) Change the current working directory to path. Availability: Unix, Windows. 回答2: Perhaps this is what you are looking for: import os os.chdir(default_path) 回答3: import os print os.getcwd() # Prints the current working directory To set the working directory: os.chdir('c:\\Users\\uname\\desktop\

How to get the current directory in a C program?

冷暖自知 提交于 2019-11-26 01:13:57
问题 I\'m making a C program where I need to get the directory that the program is started from. This program is written for UNIX computers. I\'ve been looking at opendir() and telldir() , but telldir() returns a off_t (long int) , so it really doesn\'t help me. How can I get the current path in a string (char array)? 回答1: Have you had a look at getcwd()? #include <unistd.h> char *getcwd(char *buf, size_t size); Simple example: #include <unistd.h> #include <stdio.h> #include <limits.h> int main()

How do I get the directory that a program is running from?

佐手、 提交于 2019-11-25 23:12:49
问题 Is there a platform-agnostic and filesystem-agnostic method to obtain the full path of the directory from where a program is running using C/C++? Not to be confused with the current working directory. (Please don\'t suggest libraries unless they\'re standard ones like clib or STL.) (If there\'s no platform/filesystem-agnostic method, suggestions that work in Windows and Linux for specific filesystems are welcome too.) 回答1: Here's code to get the full path to the executing app: Windows: int