详解使用Python处理文件目录的相关方法
发布时间:2020-05-23 21:13:37 所属栏目:Python 来源:互联网
导读:所有文件都包含在各个不同的目录下,不过Python也能轻松处理。os模块有许多方法能帮你创建,删除和更改目录。
|
所有文件都包含在各个不同的目录下,不过Python也能轻松处理。os模块有许多方法能帮你创建,删除和更改目录。
os.mkdir("newdir")
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
# 创建目录test
os.mkdir("test")
chdir()方法
os.chdir("newdir")
例子:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
# 将当前目录改为"/home/newdir"
os.chdir("/home/newdir")
getcwd()方法: os.getcwd() 例子: #!/usr/bin/python # -*- coding: UTF-8 -*- import os # 给出当前的目录 os.getcwd() rmdir()方法
os.rmdir('dirname')
#!/usr/bin/python # -*- coding: UTF-8 -*- import os # 删除”/tmp/test”目录 os.rmdir( "/tmp/test" ) (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
