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.

path
Filter by
Sorted by
Tagged with
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.
Parand's user avatar
  • 104k
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"
Joan Venge's user avatar
  • 323k
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: "...
Brian MacKay's user avatar
  • 31.6k
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\...
BuZz's user avatar
  • 16.9k
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 ...
Ram Rachum's user avatar
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 ...
Ali's user avatar
  • 265k
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/...
Jean's user avatar
  • 22.1k
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"
izb's user avatar
  • 50.9k
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 ...
Setjmp's user avatar
  • 27.8k
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'...
Ben Gartner's user avatar
  • 14.7k
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, ...
T.J. Crowder's user avatar
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 ...
Paul Wicks's user avatar
  • 64.2k
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 ...
jameshfisher's user avatar
  • 35.7k
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 ...
Netorica's user avatar
  • 19k
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 ...
dhardy's user avatar
  • 11.6k
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', '...
Komaruloh's user avatar
  • 6,941
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 ...
Jason Kim's user avatar
  • 18.6k
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 ...
Thiago Chaves's user avatar
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 ...
vy32's user avatar
  • 29.1k
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 ...
Gary Willoughby's user avatar
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).
ThomasReggi's user avatar
  • 57.2k
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) ...
kchak's user avatar
  • 7,792
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 ...
user avatar
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 ...
Chase's user avatar
  • 68.3k
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 ...
SnAzBaZ's user avatar
  • 6,519
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 ...
ant2009's user avatar
  • 25.5k
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 ...
Jeffrey Cameron's user avatar
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("/")?
Manu's user avatar
  • 28.9k
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 ...
Vilx-'s user avatar
  • 106k
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 ...
fxp's user avatar
  • 6,932
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.
user avatar
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?
Fang-Pen Lin's user avatar
  • 13.9k
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 ...
baudtack's user avatar
  • 29.7k
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 ...
chrisg's user avatar
  • 40.8k
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 ...
bogdan's user avatar
  • 9,236
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?
pepero's user avatar
  • 7,343
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?
vdogsandman's user avatar
  • 5,347
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 ...
Piotr Lesnicki's user avatar
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...)?
Paul Tarjan's user avatar
  • 49.7k
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.
mat_boy's user avatar
  • 13.3k
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 ...
user2214609's user avatar
  • 4,873
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[...
Yogesh Pingle's user avatar
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
VoidPointer's user avatar
  • 17.7k
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 ...
Oddthinking's user avatar
  • 24.9k
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 ...
KMC's user avatar
  • 19.9k
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 ...
Simon Suh's user avatar
  • 10.7k
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/...
devB78's user avatar
  • 12.1k
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 ...
Sharon Watinsan's user avatar
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 ...
Frank's user avatar
  • 65.2k
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 ...
user987137's user avatar
  • 2,967

1
2 3 4 5
457