@ -1448,6 +1448,8 @@ value = args.<name>
< / code > < / pre > < / div >
< pre > < code class = "python language-python hljs" > < str> = getcwd() < span class = "hljs-comment" > # Returns the current working directory.< / span >
< str> = path.join(< span class = "hljs-string" > '< path> '< / span > , ...) < span class = "hljs-comment" > # Joins two or more pathname components.< / span >
< str> = path.abspath(< span class = "hljs-string" > '< path> '< / span > ) < span class = "hljs-comment" > # Return an absolute path.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < bool> = path.exists(< span class = "hljs-string" > '< path> '< / span > )
< bool> = path.isfile(< span class = "hljs-string" > '< path> '< / span > )
@ -1456,6 +1458,10 @@ value = args.<name>
< pre > < code class = "python language-python hljs" > < list> = listdir(< span class = "hljs-string" > '< path> '< / span > ) < span class = "hljs-comment" > # Returns filenames located at path.< / span >
< list> = glob(< span class = "hljs-string" > '< pattern> '< / span > ) < span class = "hljs-comment" > # Returns paths matching the wildcard pattern.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < str> = path.basename(< span class = "hljs-string" > '< path> '< / span > ) < span class = "hljs-comment" > # Returns final component.< / span >
< str> = path.dirname(< span class = "hljs-string" > '< path> '< / span > ) < span class = "hljs-comment" > # Returns path without final component.< / span >
< str> = path.splitext(< span class = "hljs-string" > '< path> '< / span > )[< span class = "hljs-number" > 1< / span > ] < span class = "hljs-comment" > # Returns final component's extension.< / span >
< / code > < / pre >
< div > < h3 id = "pathlib" > Pathlib< / h3 > < pre > < code class = "python language-python hljs" > < span class = "hljs-keyword" > from< / span > pathlib < span class = "hljs-keyword" > import< / span > Path
< / code > < / pre > < / div >
@ -1463,8 +1469,9 @@ value = args.<name>
< Path> = < Path> / < span class = "hljs-string" > '< dir> '< / span > / < span class = "hljs-string" > '< file> '< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < Path> = Path() < span class = "hljs-comment" > # Or: Path('.')< / span >
< Path> = Path.cwd() < span class = "hljs-comment" > # Returns absolute cwd. Or: Path().resolve()< / span >
< Path> = < Path> .resolve() < span class = "hljs-comment" > # Returns absolute Path without symlinks.< / span >
< Path> = < Path> .parent < span class = "hljs-comment" > # Returns p ath without final component.< / span >
< Path> = < Path> .parent < span class = "hljs-comment" > # Returns P ath without final component.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < bool> = < Path> .exists()
< bool> = < Path> .is_file()
@ -1481,9 +1488,10 @@ value = args.<name>
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < file> = open(< Path> ) < span class = "hljs-comment" > # Opens the file and returns a file object.< / span >
< / code > < / pre >
< div > < h3 id = "direntry" > DirEntry< / h3 > < pre > < code class = "python language-python hljs" > < iter> = os.scandir(path=< span class = "hljs-string" > '.'< / span > ) < span class = "hljs-comment" > # Returns DirEntry objects located at path.< / span >
< div > < h3 id = "direntry" > DirEntry< / h3 > < p > < strong > Using scandir() instead of listdir() can significantly increase the performance of code that also needs file type or file attribute information.< / strong > < / p > < p re> < code class = "python language-python hljs" > < iter> = os.scandir(path=< span class = "hljs-string" > '.'< / span > ) < span class = "hljs-comment" > # Returns DirEntry objects located at path.< / span >
< / code > < / pre > < / div >
< pre > < code class = "python language-python hljs" > < bool> = < DirEntry> .is_file()
< bool> = < DirEntry> .is_dir()
< / code > < / pre >