用于与文件系统交互的python库
disk的Python项目详细描述
磁盘
磁盘是一个python库,用于以面向对象的方式与文件系统交互。我知道您可以使用os和os.path来完成所有这些操作,但我发现它们的用法很难记住,而且不太面向对象。
安装
您可以使用pip安装磁盘。
pip install disk
用法
磁盘是文件系统的面向对象接口。所有文件和目录(文件夹)都被视为path对象。除了根目录之外的任何路径都有一个父目录:它所在的目录。目录有子目录,有些是文件,有些是子目录。
路径
通常我们希望从当前工作目录开始:
fromdiskimportPathcurrent_directory=Path.get_current_directory()# ls or dir:print(current_directory.list())# get the first subdirectory:first_subdirectory=current_directory.directories[0]# get the parent directory:parent_directory=current_directory.parent_directory