22,793 questions
5803
votes
28
answers
4.0m
views
How do I create a directory, and any missing parent directories?
How do I create a directory at a given path, and also create any missing parent directories along that path? For example, the Bash command mkdir -p /path/to/nested/directory does this.
1388
votes
23
answers
2.5m
views
Extract file name from path, no matter what the os/path format
Which Python library can I use to extract filenames from paths, no matter what the operating system or path format could be?
For example, I'd like all of these paths to return me c:
a/b/c/
a/b/c
\a\...
1112
votes
24
answers
2.2m
views
How to permanently set $PATH on Linux/Unix [closed]
On Linux, how can I add a directory to the $PATH so it remains persistent across different sessions?
Background
I'm trying to add a directory to my path so it will always be in my Linux path. I've ...
1078
votes
12
answers
1.6m
views
How to get an absolute file path in Python
Given a path such as "mydir/myfile.txt", how do I find the file's absolute path in Python? E.g. on Windows, I might end up with:
"C:/example/cwd/mydir/myfile.txt"
1051
votes
28
answers
1.1m
views
How to use to find files recursively?
I would like to list all files recursively in a directory. I currently have a directory structure like this:
src/main.c
src/dir/file1.c
src/another-dir/file2.c
src/another-dir/nested/files/file3.c
I'...
950
votes
33
answers
929k
views
Setting environment variables on OS X
What is the proper way to modify environment variables like PATH in OS X?
I've looked on Google a little bit and found three different files to edit:
/etc/paths
~/.profile
~/.tcshrc
I don't even ...
851
votes
14
answers
684k
views
How can I set the current working directory to the directory of the script in Bash?
I'm writing a Bash script. I need the current working directory to always be the directory that the script is located in.
The default behavior is that the current working directory in the script is ...
771
votes
23
answers
2.6m
views
Adding a directory to the PATH environment variable in Windows
I am trying to add C:\xampp\php to my system PATH environment variable in Windows.
I have already added it using the Environment Variables dialog box.
But when I type into my console:
path
it doesn't ...
696
votes
46
answers
388k
views
Accessing nested JavaScript objects and arrays by string path
I have a data structure like this :
var someObject = {
'part1' : {
'name': 'Part 1',
'size': '20',
'qty' : '50'
},
'part2' : {
'name': 'Part 2',
'...
659
votes
33
answers
645k
views
How to get the path of a running JAR file?
My code runs inside a JAR file, say foo.jar, and I need to know, in the code, in which folder the running foo.jar is.
So, if foo.jar is in C:\FOO\, I want to get that path no matter what my current ...
608
votes
9
answers
448k
views
Node.js check if path is file or directory
I can't seem to get any search results that explain how to do this.
All I want to do is be able to know if a given path is a file or a directory (folder).
537
votes
11
answers
450k
views
Folder management with r : Check existence of directory and create it if it doesn't exist
I often find myself writing R scripts that generate a lot of output. I find it cleaner to put this output into its own directory(s). What I've written below will check for the existence of a directory ...
509
votes
11
answers
479k
views
Why does the 260 character path length limit exist in Windows?
I have come up against this problem a few times at inopportune moments:
Trying to work on open source Java projects with deep paths
Storing deep Fitnesse wiki trees in source control
An error trying ...
496
votes
11
answers
464k
views
C# getting the path of %AppData%
C# 2008 SP1
I am using the code below:
dt.ReadXml("%AppData%\\DateLinks.xml");
However, I am getting an exception that points to the location of where my application is running from:
Could not ...
482
votes
26
answers
1.7m
views
How can I find where Python is installed on Windows?
I want to find out my Python installation path on Windows. For example:
C:\Python25
How can I find where Python is installed?
475
votes
4
answers
526k
views
Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference?
Can anyone explain the difference between Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\") and Server.MapPath("/")?
446
votes
21
answers
1.0m
views
Relative paths in Python [duplicate]
I'm building a simple helper script for work that will copy a couple of template files in our code base to the current directory. I don't, however, have the absolute path to the directory where the ...
415
votes
10
answers
394k
views
How to get only the last part of a path in Python?
In python, suppose I have a path like this:
/folderA/folderB/folderC/folderD/
How can I get just the folderD part?
390
votes
25
answers
221k
views
Convert absolute path into relative path given a current directory using Bash
Example:
absolute="/foo/bar"
current="/foo/baz/foo"
# Magic
relative="../../bar"
How do I create the magic (hopefully not too complicated code...)?
377
votes
1
answer
1.3m
views
Display current path in terminal only [closed]
I'm SSH'd into a computer, so I can't use a GUI to access the path name. Is there a way that you can see the path directly on terminal without having to use Nautilus?
360
votes
13
answers
796k
views
Get current folder path
I want to create a program that converts files. I would like the user to be able to place the executable file in any directory, and when executing that program (double-clicking on the .exe) I want the ...
323
votes
23
answers
259k
views
How to construct a relative path in Java from two absolute paths (or URLs)?
Given two absolute paths, e.g.
/var/data/stuff/xyz.dat
/var/data
How can one create a relative path that uses the second path as its base? In the example above, the result should be: ./stuff/xyz.dat
315
votes
13
answers
182k
views
xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist
I'm having Xcode issues when I try to use Homebrew and Git:
xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist, use xcode-select --switch path/...
310
votes
12
answers
692k
views
How do I get the file name from a String containing the Absolute file path?
String variable contains a file name, C:\Hello\AnotherFolder\The File Name.PDF. How do I only get the file name The File Name.PDF as a String?
I planned to split the string, but that is not the ...
308
votes
5
answers
807k
views
How should I write a Windows path in a Python string literal?
Suppose I need to refer to the path C:\meshes\as. If I try writing that directly, like "C:\meshes\as", I encounter problems - either some exception, or the path just doesn't work. Is this ...