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.

A path represents a unique file system location using the directory tree hierarchy expressed in a string of characters in which path components, separated by a delimiting character, represent each directory. The delimiting character is most commonly a slash /, a backslash \, or a colon :.

A PATH (all upper case, ) in the Linux, UNIX-like operating systems and Windows contains list of directories, where the shell searches through, when a command is executed. The executables are stored in different directories in the OS. On UNIX-like OS the directories are separated by colon, on Windows by semi-colon.

Examples

Simple way to show the $PATH variable is:

echo "$PATH"
printf "%s\n" "$PATH"

A typical PATH looks like:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin

More generally, a path is a sequence of directions that, when followed in order, reach a certain object or location.

In addition to file system paths, there are paths through a tree:

root->left->right->right->left

or, again more generally, a set of attributes on an object.


There might be some other contexts where the term "path" is used to described something non-URI and non-directory related which are not covered by the general description.

One case would be in a context such as in the SCADA software, Ignition, where the term "path" is generally used to refer to tag-path - as Tag is the basic unit in the software, forming a hierarchical system like directory. Typical tag-path in Ignition look like this:

BaseFolder/MyTag

Or, more complexly when tag is not in the BaseFolder but referred from another "Parent" Tag:

BaseFolder/MyAdvanceUDTTag/MyBaseUDTTag/MyTag
19410 questions
445
votes
12 answers

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.
novicer
415
votes
21 answers

Relative paths in Python

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 templates are stored. I do have a relative path…
baudtack
  • 29,062
  • 9
  • 53
  • 61
412
votes
16 answers

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 it only stores the /new_sandbox/ part of the…
chrisg
  • 40,337
  • 38
  • 86
  • 107
404
votes
23 answers

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
  • 13,420
  • 15
  • 66
  • 96
402
votes
16 answers

How do you properly determine the current script directory?

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 are some problems: __file__ is not defined if the…
bogdan
  • 9,056
  • 10
  • 37
  • 42
382
votes
10 answers

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
  • 7,095
  • 7
  • 41
  • 72
378
votes
1 answer

Display current path in terminal only

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
  • 5,289
  • 8
  • 21
  • 21
359
votes
15 answers

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 manually or something involving trying to execute it…
Piotr Lesnicki
  • 9,442
  • 2
  • 28
  • 26
353
votes
25 answers

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
  • 48,968
  • 59
  • 172
  • 213
350
votes
4 answers

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
  • 12,998
  • 22
  • 72
  • 116
334
votes
13 answers

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 program to process all the files within the…
user2214609
  • 4,713
  • 9
  • 34
  • 41
318
votes
23 answers

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
  • 17,651
  • 15
  • 54
  • 58
306
votes
8 answers

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 hopefully the answer should be platform independent).…
Oddthinking
  • 24,359
  • 19
  • 83
  • 121
305
votes
12 answers

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 I just not use it if that's all it's doing?
Simon Suh
  • 10,599
  • 25
  • 86
  • 110
305
votes
10 answers

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 following code to split the path by '\' and then split…
KMC
  • 19,548
  • 58
  • 164
  • 253