@ -1453,32 +1453,45 @@ value = args.<name>
< bool> = path.isfile(< span class = "hljs-string" > '< path> '< / span > )
< bool> = path.isdir(< span class = "hljs-string" > '< path> '< / span > )
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < list> = listdir(< span class = "hljs-string" > '< path> '< / span > ) < span class = "hljs-comment" > # List of filenames located at path.< / span >
< list> = glob(< span class = "hljs-string" > '< pattern> '< / span > ) < span class = "hljs-comment" > # Filename s matching the wildcard pattern.< / span >
< 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 path s matching the wildcard pattern.< / 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 >
< pre > < code class = "python language-python hljs" > cwd = Path()
< Path> = Path(< span class = "hljs-string" > '< path> '< / span > [, < span class = "hljs-string" > '< path> '< / span > , < Path> , ...])
< pre > < code class = "python language-python hljs" > < Path> = Path(< span class = "hljs-string" > '< path> '< / span > [, < span class = "hljs-string" > '< path> '< / span > , < Path> , ...])
< 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> .resolve() < span class = "hljs-comment" > # Returns absolute Path without symlinks.< / span >
< Path> = < Path> .parent < span class = "hljs-comment" > # Returns path without final component.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < bool> = < Path> .exists()
< bool> = < Path> .is_file()
< bool> = < Path> .is_dir()
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < iter> = < Path> .iterdir() < span class = "hljs-comment" > # Returns dir contents as Path objects.< / span >
< iter> = < Path> .glob(< span class = "hljs-string" > '< pattern> '< / span > ) < span class = "hljs-comment" > # Returns Paths matching the wildcard pattern.< / span >
< pre > < code class = "python language-python hljs" > < iter> = < Path> .iterdir() < span class = "hljs-comment" > # Returns dir contents as relative (not true) Path objects.< / span >
< iter> = < Path> .glob(< span class = "hljs-string" > '< pattern> '< / span > ) < span class = "hljs-comment" > # Returns relative Paths matching the wildcard pattern.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < str> = str(< Path> ) < span class = "hljs-comment" > # Path as a string.< / span >
< str> = < Path> .name < span class = "hljs-comment" > # F inal component.< / span >
< str> = < Path> .stem < span class = "hljs-comment" > # F inal component without extension.< / span >
< str> = < Path> .suffix < span class = "hljs-comment" > # F inal component's extension.< / span >
< tup.> = < Path> .parts < span class = "hljs-comment" > # A ll components as strings.< / span >
< pre > < code class = "python language-python hljs" > < str> = str(< Path> ) < span class = "hljs-comment" > # Returns Path as a string.< / span >
< str> = < Path> .name < span class = "hljs-comment" > # Returns f inal component.< / span >
< str> = < Path> .stem < span class = "hljs-comment" > # Returns f inal component without extension.< / span >
< str> = < Path> .suffix < span class = "hljs-comment" > # Returns f inal component's extension.< / span >
< tup.> = < Path> .parts < span class = "hljs-comment" > # Returns a ll components as strings.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < Path> = < Path> .resolve() < span class = "hljs-comment" > # Returns absolute path without symlinks.< / span >
< Path> = < Path> .parent < span class = "hljs-comment" > # Returns path without final component.< / span >
< file> = open(< Path> ) < span class = "hljs-comment" > # Opens the file and returns a file object.< / span >
< 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 >
< / code > < / pre > < / div >
< pre > < code class = "python language-python hljs" > < bool> = < DirEntry> .is_file()
< bool> = < DirEntry> .is_dir()
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < str> = < DirEntry> .path < span class = "hljs-comment" > # Returns relative path as a string.< / span >
< str> = < DirEntry> .name < span class = "hljs-comment" > # Returns final component.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < Path> = Path(< DirEntry> ) < span class = "hljs-comment" > # Returns relative Path object.< / span >
< file> = open(< DirEntry> ) < span class = "hljs-comment" > # Opens the file and returns a file object.< / span >
< / code > < / pre >
< div > < h2 id = "oscommands" > < a href = "#oscommands" name = "oscommands" > #< / a > OS Commands< / h2 > < div > < h3 id = "filesanddirectories" > Files and Directories< / h3 > < ul >
< li > < strong > Paths can be either strings, Paths, or DirEntry objects.< / strong > < / li >
@ -1492,26 +1505,14 @@ value = args.<name>
os.mkdir(< path> , mode=< span class = "hljs-number" > 0o777< / span > ) < span class = "hljs-comment" > # Creates a directory. Mode is in octal.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > shutil.copy(from, to) < span class = "hljs-comment" > # Copies the file.< / span >
shutil.copytree(from, to) < span class = "hljs-comment" > # Copies the entire directory tree .< / span >
shutil.copytree(from, to) < span class = "hljs-comment" > # Copies the directory.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > os.rename(from, to) < span class = "hljs-comment" > # Renames the file or directory.< / span >
os.replace(from, to) < span class = "hljs-comment" > # Same, but overwrites 'to' if it exists.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > os.remove(< path> ) < span class = "hljs-comment" > # Deletes the file.< / span >
os.rmdir(< path> ) < span class = "hljs-comment" > # Deletes empty directory.< / span >
shutil.rmtree(< path> ) < span class = "hljs-comment" > # Deletes the entire directory tree.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < iter> = os.scandir(path=< span class = "hljs-string" > '.'< / span > ) < span class = "hljs-comment" > # Returns os.DirEntry objects located at path.< / span >
< / code > < / pre >
< div > < h4 id = "direntry" > DirEntry:< / h4 > < pre > < code class = "python language-python hljs" > < bool> = < DirEntry> .is_file()
< bool> = < DirEntry> .is_dir()
< / code > < / pre > < / div >
< pre > < code class = "python language-python hljs" > < str> = < DirEntry> .path < span class = "hljs-comment" > # Path as a string.< / span >
< str> = < DirEntry> .name < span class = "hljs-comment" > # Final component.< / span >
< / code > < / pre >
< pre > < code class = "python language-python hljs" > < Path> = Path(< DirEntry> ) < span class = "hljs-comment" > # Path object.< / span >
< file> = open(< DirEntry> ) < span class = "hljs-comment" > # File object.< / span >
shutil.rmtree(< path> ) < span class = "hljs-comment" > # Deletes non-empty directory.< / span >
< / code > < / pre >
< div > < h3 id = "shellcommands" > Shell Commands< / h3 > < pre > < code class = "python language-python hljs" > < span class = "hljs-keyword" > import< / span > os
< str> = os.popen(< span class = "hljs-string" > '< shell_command> '< / span > ).read()