python怎么创建文件夹视频_怎么用python创建文件夹

Python中创建文件夹的方法:import os

def mkdir(path):

folder = os.path.exists(path)

if not folder:                   #判断是否存在文件夹如果不存在则创建为文件夹

os.makedirs(path)            #makedirs 创建文件时如果路径不存在会创建这个路径

print "---  new folder...  ---"

print "---  OK  ---"

else:

print "---  There is this folder!  ---"

file = "G:xxooest"

mkdir(file)             #调用函数

os.getcwd()可以查看py文件所在路径;

在os.getcwd()后边 加上 [:-4] + 'xxoo' 就可以在py文件所在路径下创建 xxoo文件夹import os

folder = os.getcwd()[:-4] + 'new_folderest'

#获取此py文件路径,在此路径选创建在new_folder文件夹中的test文件夹

if not os.path.exists(folder):

os.makedirs(folder)

创建txt文件

在桌面创建一个名字为 new 的txt文件import os

file = open('C:UsersAdministratorDesktop' + 'new' + '.txt','w')

file.close()

更多技术请关注云海天Python教程。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值