Python中的OS模块提供了用于创建和删除目录(文件夹),获取其内容,更改和标识当前目录等功能。 http://python101.pythonlibrary.org/chapter16_os.html https://www.tutorialsteacher.com/python/os-module os.mkdir()函数:创建一个新目录 >>> os.mkdir('c:\\123') os.getcwd()函数:获取当前工作目录 >>> os.getcwd() os.chdir()函数:更改当前工作目录 >>> os.chdir("c:\\123") >>> os.chdir("..") os.rmdir()函数:删除空目录,不能删除当前所在目录 >>> os.rmdir("123") os.listdir()函数:返回指定目录下的所有文件和目录的列表,未指定任何目录,则将返回当前所在目录 >>> os.listdir("C:\python38") >>> os.listdir() Python检查文件或目录是否存在 os.path.exists() 使用path.exists可以快速检查文件或目录是否存在 os.path.isfile() 我们可以使用isfile命令来检查给定的输入是文件还是目录。 os.path.isdir() 如果我们想确认给定路径指向目录,我们可以使用os.path.dir()函数 import os from os import path def main ( ) : # Print the name of the OS print ( os . name ) #Check for item existence and type print ( "Item exists:" + str ( path. exists ( "1.xlsx" ) ) ) print ( "Item is a f...