lkpruby.blogg.se

Python disk catalog
Python disk catalog





list_from_pickle = Path ( 'my_list.pickle' ). To load an object from a Pickle file located at a Path you can run the load function of the Path. save ( my_list, method = 'pickle' ) Path ( 'my_list.dill' ). Save function of the Path which saves the object right at the location of Path. To save a Python object as a Pickle file using the pickle or dill library you can just use the If the name argument is not provided the file or directory the Path points to will be deleted: path. The file or directory inside the Path with that name will be deleted: path. The delete function moves a file or directory to the trash. The default value of ignore_if_exists is True. make_parent_directory ( ignore_if_exists = True ) This is when make_parent_directory becomes handy: path. Sometimes you need to create a new file at a Path that doesn't already exist, i.e. You can also create a directory at the location of the Path object by letting the nameĪrgument take its default value of None: path. make_directory ( name = 'new_directory' ) With the name of the new directory as the name argument: path. To create a new directory inside a Path that is also a directory, use make_directory The parent directory is the directory a Path (either file or directory) is inside of. To get the files inside a directory use the files attribute which returns a list of Paths: files = path. To get the sub-directories of a directory use the directories attribute which returns a list of Paths: subdirectories = path. Ls is for linux people, dir is for windows people, and list is for literal people. get_current_directory () list, dir, lsĪll of the above methods do the same thing Usually we want to start in the current working directory: path = Path.

python disk catalog

from disk import Path path = Path ( 'C: \\ ' ) get_current_directory The Path object points to an existing or non-existing file or directory. You can use pip to install Disk: pip install diskĪll files and directories (folders) are considered Path objects.Īny path except the root, has a parent: the directory it is in.ĭirectories have children, some of them are files and some are subdirectories. I know you can use os and os.path to do all of these but I find their usage hard to rememberĪnd true to object oriented principles. Disk is a Python library for interacting with the file system in an object oriented manner.







Python disk catalog