1010
1111
1212def parse_path (path , prefix = "" ):
13- """Parse a path into its components.
13+ r """Parse a path into its components.
1414
1515 If the path doesn't end with the pathsep, it is assumed being a file!
1616 No tests based on existing files are done, as this is supposed to also work
@@ -20,6 +20,11 @@ def parse_path(path, prefix=""):
2020 *Script Parameter* `#@ File`) for either of the parameters, so it is safe to
2121 use this in ImageJ Python scripts without additional measures.
2222
23+ **WARNING**: when passing in **Windows paths** literally, make sure to
24+ declare them as **raw strings** using the `r""` notation, otherwise
25+ unexpected things might happen if the path contains sections that Python
26+ will interpret as escape sequences (e.g. `\n`, `\t`, `\u2324`, ...).
27+
2328 Parameters
2429 ----------
2530 path : str or str-like
@@ -64,6 +69,7 @@ def parse_path(path, prefix=""):
6469 'parent': '/tmp/',
6570 'path': '/tmp/foo/'}
6671
72+
6773 POSIX-style path to a directory:
6874
6975 >>> parse_path('/tmp/foo/')
@@ -76,17 +82,19 @@ def parse_path(path, prefix=""):
7682 'parent': '/tmp/',
7783 'path': '/tmp/foo/'}
7884
85+
7986 Windows-style path to a file:
8087
81- >>> parse_path('C:\\ Temp\\ foo \ \ file.ext')
82- {'dname': 'foo ',
88+ >>> parse_path(r 'C:\Temp\new \file.ext')
89+ {'dname': 'new ',
8390 'ext': '.ext',
8491 'fname': 'file.ext',
85- 'full': 'C:/Temp/foo /file.ext',
92+ 'full': 'C:/Temp/new /file.ext',
8693 'basename': 'file',
87- 'orig': 'C:\\ Temp\\ foo \\ file.ext',
94+ 'orig': 'C:\\Temp\\new \\file.ext',
8895 'parent': 'C:/Temp/',
89- 'path': 'C:/Temp/foo/'}
96+ 'path': 'C:/Temp/new/'}
97+
9098
9199 Special treatment for *OME-TIFF* suffixes:
92100
0 commit comments