Size: 1892
Comment:
|
Size: 4315
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 11: | Line 11: |
== Usage == | == Functions == |
Line 13: | Line 13: |
=== AbsPath === See [[Python/PathLib#Absolute|Path.absolute]]. ---- === BaseName === See [[Python/PathLib#Name|Path.name]]. ---- === CommonPath === ---- === CommonPrefix === ---- === DirName === See [[Python/PathLib#Parent|Path.parent]]. ---- === Exists === See [[Python/PathLib#Exists|Path.exists]]. ---- === ExpandUser === See [[Python/PathLib#ExpandUser|Path.expanduser]] and [[Python/PathLib#Home|Path.home]]. ---- === ExpandVars === ---- === GetATime === ---- === GetCTime === ---- === GetMTime === ---- === GetSize === ---- === IsAbs === See [[Python/PathLib#Is_Absolute|Path.is_absolute]]. ---- === IsDir === See [[Python/PathLib#Is_Dir|Path.is_dir]]. ---- === IsFile === See [[Python/PathLib#Is_File|Path.is_file]]. ---- === IsLink === See [[Python/PathLib#Is_SymLink|Path.is_symlink]]. ---- === Join === See [[Python/PathLib#JoinPath|Path.joinpath]]. ---- === NormCase === ---- === NormPath === ---- === RealPath === See [[Python/PathLib#Resolve|Path.resolve]]. ---- === RelPath === See [[Python/PathLib#Relative_To|Path.relative_to]]. ---- === SameFile === See [[Python/PathLib#SameFile|Path.samefile]]. ---- === SameOpenFile === ---- === SameStat === ---- === Split === ---- === SplitDrive === ---- === SplitExt === See [[Python/PathLib#Stem|Path.stem]] and [[Python/PathLib#Suffix|Path.suffix]]. |
||'''Function''' ||'''Example''' || ||`abspath()` ||see [[Python/PathLib#Absolute|Path.absolute]] || ||`basename()` ||see [[Python/PathLib#Name|Path.name]] || ||`commonpath()` ||`commonpath('/usr/lib', '/usr/local')` returns `'/usr'` || ||`commonprefix()`||`commonprefix('/usr/lib', '/usr/local')` returns `'/usr/l'` || ||`dirname()` ||see [[Python/PathLib#Parent|Path.parent]] || ||`exists()` ||see [[Python/PathLib#Exists|Path.exists]] || ||`expanduser()` ||see [[Python/PathLib#ExpandUser|Path.expanduser]] and [[Python/PathLib#Home|Path.home]] || ||`expandvars()` ||variable references like `$name` and `${name}` (and `%name%` on Windows) are replaced with variable values if defined|| ||`getatime()` ||last access time of a file, as a [[Python/Builtins/Types#Float|float]] representing seconds since the epoch || ||`getctime()` ||last metadata change time (Unix) or creation time (Windows) of a file || ||`getmtime()` ||last modification time of a file || ||`getsize()` ||size of a file || ||`isabs()` ||see [[Python/PathLib#Is_Absolute|Path.is_absolute]] || ||`isdir()` ||see [[Python/PathLib#Is_Dir|Path.is_dir]] || ||`isfile()` ||see [[Python/PathLib#Is_File|Path.is_file]] || ||`islink()` ||see [[Python/PathLib#Is_SymLink|Path.is_symlink]] || ||`join()` ||see [[Python/PathLib#JoinPath|Path.joinpath]] || ||`normcase()` ||on Windows only, push letters to lowercase and replace forward slashes (`/`) with backslashes (`\`) || ||`normpath()` ||collapse redundant separators and up-level references || ||`realpath()` ||see [[Python/PathLib#Resolve|Path.resolve]] || ||`relpath()` ||see [[Python/PathLib#Relative_To|Path.relative_to]] || ||`samefile()` ||see [[Python/PathLib#SameFile|Path.samefile]] || ||`sameopenfile()`||test if two open file objects are the same || ||`samestat()` ||test if stat tuples (as returned by `os.fstat()`, `os.lstat()`, or `os.stat()`) are the same || ||`split()` ||`split('/usr/bin')` returns `('/usr/', 'bin', )`; `split('/usr/')` returns `('/usr/', '', )` || ||`splitdrive()` ||on Windows only, split the drive letter or UNC host name off || ||`splitext()` ||see [[Python/PathLib#Stem|Path.stem]] and [[Python/PathLib#Suffix|Path.suffix]] || |
Line 207: | Line 50: |
[[https://pymotw.com/3/os.path/|Python Module of the Day article for os.path]] |
Python Os Path
os.path is a module providing filesystem APIs.
Contents
Functions
Function |
Example |
abspath() |
see Path.absolute |
basename() |
see Path.name |
commonpath() |
commonpath('/usr/lib', '/usr/local') returns '/usr' |
commonprefix() |
commonprefix('/usr/lib', '/usr/local') returns '/usr/l' |
dirname() |
see Path.parent |
exists() |
see Path.exists |
expanduser() |
see Path.expanduser and Path.home |
expandvars() |
variable references like $name and ${name} (and %name% on Windows) are replaced with variable values if defined |
getatime() |
last access time of a file, as a float representing seconds since the epoch |
getctime() |
last metadata change time (Unix) or creation time (Windows) of a file |
getmtime() |
last modification time of a file |
getsize() |
size of a file |
isabs() |
see Path.is_absolute |
isdir() |
see Path.is_dir |
isfile() |
see Path.is_file |
islink() |
see Path.is_symlink |
join() |
see Path.joinpath |
normcase() |
on Windows only, push letters to lowercase and replace forward slashes (/) with backslashes (\) |
normpath() |
collapse redundant separators and up-level references |
realpath() |
see Path.resolve |
relpath() |
see Path.relative_to |
samefile() |
see Path.samefile |
sameopenfile() |
test if two open file objects are the same |
samestat() |
test if stat tuples (as returned by os.fstat(), os.lstat(), or os.stat()) are the same |
split() |
split('/usr/bin') returns ('/usr/', 'bin', ); split('/usr/') returns ('/usr/', '', ) |
splitdrive() |
on Windows only, split the drive letter or UNC host name off |
splitext() |
see Path.stem and Path.suffix |
See also
Python os.path module documentation
Python Module of the Day article for os.path