通常运用于批量创建目录使用.
判断:os.path.exists(train_dir)
创建:os.mkdir(train_dir)
拷贝:shutil.copy()
判断是否存在该文件
base_dir = './dataset/'
train_dir = os.path.join(base_dir, 'train')
test_dir = os.path.join(base_dir, 'test')
# 创建train和test目录
if not os.path.exists(train_dir):
os.mkdir(train_dir)
if not os.path.exists(test_dir):
os.mkdir(test_dir)
再通过循环进行创建
species = ['cloudy', 'rain', 'shine', 'sunrise']
# 分别在train和test目录下创建目标目录
for train_or_test in['train', 'test']:
for spec in species:
os.mkdir(os.path.join(train_dir, spec))
拷贝
# python中自带的拷贝工具
import shutil
shutil.copy('原文件地址', '目标地址')