Path handling¶
File system path handling
Create¶
Create or generate path(s)
| Action | Code | Details |
|---|---|---|
| Current working directory |
|
Can be set using os.chdir() |
| From directory and given file name |
|
|
| Temporary file path |
|
|
| Temporary file path in directory |
|
|
| Temporary file path with extension (suffix) |
|
|
| Temporary directory path |
|
|
| Temporary directory path in directory |
|
|
| Directory path obtained interactively from user via dialog |
|
withdraw() is needed to prevent an annoying empty window from opening |
| File path obtained interactively from user via dialog |
|
withdraw() is needed to prevent an annoying empty window from opening |
Test¶
| Action | Code | Details |
|---|---|---|
| File/dir exists |
|
|
| File path |
|
|
| Directory path |
|
|
| Absolute path |
|
|
| Paths refer to same file |
|
|
| Is parent of path |
|
|
| Is child of path |
|
Derive¶
Manipulate a path
| Action | Code | Details |
|---|---|---|
| Filename |
|
Returns derp.csv |
| Filename without extension |
|
Returns derp |
| File extension |
|
Returns .csv |
| Normalize path |
|
|
| Absolute path |
|
Paths are relative to the working directory |
| Canonical path (resolving symlinks) |
|
|
| Parent path |
|
Returns C:\Files |
| Parent directory name |
|
Returns Files |
| Get common parent path between two or more paths |
|
|
| Relative path to directory |
|
|
| Join path with subdirectories and/or file |
|
|
| File path without extension |
|
Extract¶
All snippets return a list of string paths
| Action | Code | Details |
|---|---|---|
| File names |
|
|
| File names that match Unix filter |
|
|
| File names that match regex pattern |
|
|
| File paths |
|
|
| File paths that match Unix filter |
|
|
| File paths that match Unix filter, including nested entries (recursive) |
|
The **\ is required for recursive search to do anything. |
| File paths that match regex pattern |
|
|
| Split path into parent path and basename |
|
|
| Split path into file path and extension |
|