Pathnames

Probably more than you wanted to know

Files on Unix systems all live in a single tree. Hard drives, networked filesystems and imaginary files invented by the kernel are all mounted onto the same tree.

There are two types of file path: absolute paths (which start with a slash) and relative paths (which don't). And there's one type of separator in paths, the forward slash.

Microsoft Windows is... different.

Dealing with the last issue first, the busybox-w32 README says:

The reasoning here is that Windows itself mostly accepts forward slashes in paths. There are internal APIs that require the use of backslashes and there are one or two weird special cases where backslashes must be used, but busybox-w32 tries to hide these quirks.

On the other hand, the Unix shell uses the backslash as an escape character, which makes using them in paths inconvenient. You either need to use double backslashes or put your path in single quotes so the backslash isn't treated as special. Using forward slashes is much simpler.

As we said above Unix systems have a single tree of files. Windows has multiple trees. And trees have roots. There are two types of root:

Drive letters (e.g. C:)
represent hard disks and removable media like floppy disks (ask your grandparents) and USB sticks.
Shares (e.g. //HOST/Share)
represent networked filesystems. Paths of this form are known as UNC paths (where UNC stands for Universal Naming Convention).

With this knowledge we can define an absolute path in Windows: it's one that starts with a root specifier (drive or share) followed by a slash. Thus the following are absolute paths:

   C:/Users/rmy
   C:/Windows/System32
   //NAS/Media/thing.mp4
An absolute path is an unambiguous reference to a file on a drive or a networked filesystem.

Before looking at relative paths in Windows there's one other concept we need to consider: the current working directory.

So, finally, we can define relative paths in Windows. (And remember, there are two types of root: a drive or a share):

Supporting these different types of relative path has been a work in progress for a number of years. There are probably still a few corner cases that don't work too well but the situation is much better and more consistent than it was before.
Ron Yorston
10th February 2021