Python For Sysadmins Cheat Sheet
by shash via [Link]/18578/cs/15129/
OS Module [Link] module
[Link] gives the current working directory as the sting [Link][Link] ("folder1", "folder2", This takes the folder list and joins
value. "folder3", "filename") them to give a path name
[Link]cwd() gives the current working directory as the sting [Link]h.abspath("filename") this gives the absolute path of the file
value [Link]h.isabs("filepath") gives true of false for the abs path
[Link]ir("Dir loc") takes in directory location and changes the
[Link]h.relpath("filepath") gives relative path for the 2 paths
working directory
you give.
[Link]tdir("filename") gives s the list of all the files.
[Link]h.exists("Filename") gives true or false for the file name
[Link]edirs("folderna creates the folders.
[Link]h.isfile("filepath") true if the path is file
mes")
[Link]h.isdir("filepath") true if the path is folder
[Link]ink("filename") deletes a file
[Link]h.getsize("filename") gives the size in bytes
[Link]ir("folder") deletes a folder.
[Link]k("folder name") this returns foldername, subfolders and files in it
for foldername, subfoldername, filename in [Link]k("."):
... print(foldername, subfoldername, filename)
shutil
[Link]py("source", "destination") Copies source file to
destination file
[Link]pytree("source_folder", useful for backups
"destination_Folder")
[Link]ve("source_folder", This can also be used as
"destination_folder") renaming option.
[Link]tree("dir_name") To delete a full directory we use
this
By shash Not published yet. Sponsored by [Link]
[Link]/shash/ Last updated 26th March, 2018. Learn to solve cryptic crosswords!
Page 1 of 1. [Link]