《Python基础》之OS模块

目录

前言

各种文件操作方法

1、os.path.exists()

2、os.path.join()

3、os.path.abspath(file)

4、os.path.dirname()

5、os.path.isfile()

6、os.path.isdir()

7、os.mkdir()

8、os.remove()

9、os.rmdir()


前言

本文主要介绍使用os模块中的功能操作文件或者文件夹

各种文件操作方法

1、os.path.exists()

根据路径判断目标是否存在

2、os.path.join()

路径拼接

3、os.path.abspath(file)

获取当前文件所在路径

4、os.path.dirname()

获取某文件所处的父级目录路径

5、os.path.isfile()

判断一个路径是否是文件

6、os.path.isdir()

判断一个路径是否是文件夹

7、os.mkdir()

创建一个文件夹

如果要创建一个文件,可以使用open()函数

8、os.remove()

删除文件路径

9、os.rmdir()

删除文件夹路径

相关推荐
timeDifference₇18 分钟前
Python Vibe Coding实操实验报告
开发语言·jvm·python
geovindu1 小时前
python:DecisionTree
开发语言·后端·python·算法
怒放的生命19912 小时前
代码知识库 RAG 问答系统 —— 从 0 到 1 实现教程
python·状态模式·fastapi·全栈开发·ai agent应用开发
geovindu3 小时前
python: Decision Tree Regressor
开发语言·后端·python·算法·决策树
fengkai45454 小时前
Python运维
运维·python·监控·psutil·ipy
Fancy.7614 小时前
:Python条件与循环语句学习总结
python
Wellijohn5 小时前
Python 容器选型实测:list.insert(0) 慢 925 倍,in 慢 6000 倍
python
新*5 小时前
标题全变成一级?靠编号规律找回章节边界
python·正则表达式·pdf解析·文本处理
炸膛坦客6 小时前
单片机/C/C++八股:(三十七)指针数组 和 数组指针
c语言·开发语言·c++
夜不会漫长7 小时前
C++:C++11特性
开发语言·c++·算法