# Python 文件及文件夹操作记录 ```python # coding=utf-8 import os, sys # 文件目录的斜杠,使平台无关 print os.sep # 回到上级目录 print os.path.pardir print os.path.join(os.path.dirname("__file__"), os.path.pardir) # ---------------------------------------------------------------------------------------------- # 获取文件当前路径 print os.path.dirname(os.path.abspath("__file__")) print sys.path[0] print os.getcwd() # 获得文件上级目录 print os.path.abspath(os.path.join(os.path.dirname("__file__"), os.path.pardir)) # 获取指定目录下说有文件和目录名 print os.listdir(os.getcwd()) # 分离扩展名 print os.path.splitext(os.getcwd()) # 获取路径名 print os.path.dirname(os.getcwd()) # 获取文件名 print os.path.basename(os.getcwd()) ``` Last modification:August 15th, 2020 at 04:12 pm © 允许规范转载 Support 众筹催更 ×Close Appreciate the author Sweeping payments Pay by AliPay Pay by WeChat