Questions tagged [path]
The general form of a file or directory name that specifies a unique location in a file system. In many Linux and Unix-like OS the PATH (all upper case) variable specifies the directories where executable programs are searched for.
22,818
questions
5646
votes
27
answers
3.7m
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.
1694
votes
31
answers
2.2m
views
How do I get the filename without the extension from a path in Python?
How do I get the filename without the extension from a path in Python?
"/path/to/some/file.txt" → "file"
1509
votes
41
answers
488k
views
Path.Combine for URLs?
Path.Combine is handy, but is there a similar function in the .NET framework for URLs?
I'm looking for syntax like this:
Url.Combine("http://MyUrl.com/", "/Images/Image.jpg")
which would return:
"...
1322
votes
23
answers
2.2m
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\...
1100
votes
32
answers
1.5m
views
Importing modules from parent folder
I am running Python 2.5.
This is my folder tree:
ptdraft/
nib.py
simulations/
life/
life.py
(I also have __init__.py in each folder, omitted here for readability)
How do I import the ...
1089
votes
24
answers
2.1m
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 ...
1043
votes
36
answers
1.7m
views
How to get full path of a file?
Is there an easy way I can print the full path of file.txt ?
file.txt = /nfs/an/disks/jj/home/dir/file.txt
The <command>
dir> <command> file.txt
should print
/nfs/an/disks/jj/...
1043
votes
11
answers
1.5m
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"
1037
votes
12
answers
578k
views
mkdir -p functionality in Python [duplicate]
Is there a way to get functionality similar to mkdir -p on the shell from within Python. I am looking for a solution other than a system call. I am sure the code is less than 20 lines, and I am ...
1025
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'...
939
votes
23
answers
714k
views
Reliable way for a Bash script to get the full path to itself [duplicate]
I have a Bash script that needs to know its full path. I'm trying to find a broadly-compatible way of doing that without ending up with relative or funky-looking paths. I only need to support Bash, ...
939
votes
33
answers
883k
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 ...
801
votes
13
answers
613k
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 ...
736
votes
21
answers
2.3m
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:
C:\>path
it ...
717
votes
23
answers
623k
views
How to obtain the absolute path of a file via Shell (BASH/ZSH/SH)?
Question: is there a simple sh/bash/zsh/fish/... command to print the absolute path of whichever file I feed it?
Usage case: I'm in directory /a/b and I'd like to print the full path to file c on the ...
682
votes
46
answers
373k
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
27
answers
2.0m
views
Error "'git' is not recognized as an internal or external command"
I have an installation of Git for Windows, but when I try to use the git command in Command Prompt, I get the following error:
'git' is not recognized as an internal or external command,
operable ...
648
votes
33
answers
623k
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 ...
644
votes
3
answers
483k
views
Find full path of the Python interpreter (Python executable)?
How do I find the full path of the currently running Python interpreter from within the currently executing Python script?
See How do I check which version of Python is running my script? if you are ...
601
votes
30
answers
613k
views
How to remove illegal characters from path and filenames?
I need a robust and simple way to remove illegal path and file characters from a simple string. I've used the below code but it doesn't seem to do anything, what am I missing?
using System;
using ...
584
votes
8
answers
412k
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).
533
votes
38
answers
1.0m
views
How to change the Jupyter start-up folder
I tried following the instructions given on the Jupyter Notebook documentation.
Unfortunately, I haven't been able to figure it out. Where exactly is this "start in" field?
I've a windows 7 (64 bit) ...
518
votes
5
answers
626k
views
How do I get the path of the Python script I am running in? [duplicate]
Duplicate:
In Python, how do I get the path and name of the file that is currently executing?
How do I get the path of a the Python script I am running in? I was doing dirname(sys.argv[0]), however ...
515
votes
10
answers
408k
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 ...
496
votes
23
answers
386k
views
Better way to check if a Path is a File or a Directory?
I am processing a TreeView of directories and files. A user can select either a file or a directory and then do something with it. This requires me to have a method which performs different actions ...
486
votes
11
answers
440k
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 ...
486
votes
11
answers
426k
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 ...
475
votes
4
answers
521k
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("/")?
471
votes
9
answers
311k
views
How do browser cookie domains work?
Due to weird domain/subdomain cookie issues that I'm getting, I'd like to know how browsers handle cookies. If they do it in different ways, it would also be nice to know the differences.
In other ...
466
votes
10
answers
333k
views
Get file name from absolute path in Nodejs?
How can I get the file name from an absolute path in Nodejs?
e.g. "foo.txt" from "/var/www/foo.txt"
I know it works with a string operation, like fullpath.replace(/.+\//, ''),
but ...
455
votes
12
answers
305k
views
How to combine paths in Java?
Is there a Java equivalent for System.IO.Path.Combine() in C#/.NET? Or any code to accomplish this?
This static method combines one or more strings into a path.
430
votes
24
answers
1.3m
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?
428
votes
21
answers
894k
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 ...
419
votes
16
answers
650k
views
Why doesn't os.path.join() work in this case?
The below code will not join, when debugged the command does not store the whole path but just the last entry.
os.path.join('/home/build/test/sandboxes/', todaystr, '/new_sandbox/')
When I test this ...
409
votes
16
answers
188k
views
How do you properly determine the current script directory? [duplicate]
I would like to see what is the best way to determine the current script directory in Python.
I discovered that, due to the many ways of calling Python code, it is hard to find a good solution.
Here ...
400
votes
10
answers
350k
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?
378
votes
1
answer
1.1m
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?
369
votes
15
answers
192k
views
Test if executable exists in Python?
In Python, is there a portable and simple way to test if an executable program exists?
By simple I mean something like the which command which would be just perfect. I don't want to search PATH ...
369
votes
25
answers
198k
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...)?
360
votes
4
answers
400k
views
Create a Path from String in Java7
How can I create a java.nio.file.Path object from a String object in Java 7?
I.e.
String textPath = "c:/dir1/dir2/dir3";
Path path = ?;
where ? is the missing code that uses textPath.
349
votes
13
answers
731k
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 ...
330
votes
14
answers
1.1m
views
How to get full path of selected file on change of <input type=‘file’> using javascript, jquery-ajax?
How to get full path of file while selecting file using <input type=‘file’>
<input type="file" id="fileUpload">
<script type="text/javascript">
function getFilePath(){
$('input[...
319
votes
23
answers
254k
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
313
votes
9
answers
80k
views
What is the naming standard for path components?
I keep getting myself in knots when I am manipulating paths and file names because I don’t follow a naming standard for path components.
Consider the following toy problem (Windows example, but ...
311
votes
10
answers
465k
views
Given a filesystem path, is there a shorter way to extract the filename without its extension?
I program in WPF C#. I have e.g. the following path:
C:\Program Files\hello.txt
and I want to extract hello from it.
The path is a string retrieved from a database. Currently I'm using the ...
307
votes
12
answers
236k
views
What does "./" (dot slash) refer to in terms of an HTML file path location?
I know ../ means go up a path, but what does ./ mean exactly?
I was recently going through a tutorial and it seems to be referring to just a file in the same location, so is it necessary at all? Can ...
306
votes
13
answers
176k
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/...
303
votes
13
answers
658k
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 ...
302
votes
31
answers
156k
views
Determine path of the executing script
I have a script called foo.R that includes another script other.R, which is in the same directory:
#!/usr/bin/env Rscript
message("Hello")
source("other.R")
But I want R to find that other.R no ...
295
votes
6
answers
1.4m
views
javac is not recognized as an internal or external command, operable program or batch file [closed]
I am experiencing an error while trying to compile Java programs.
I am on Windows (this is a Windows-specific problem) and I have the latest JDK installed.
I have attempted a solution involving the ...