1.获取特定路径下面特定类型文件(特定后缀名)
from glob import glob
input_dir = r''
file_list = glob(input_dir + '*.txt')
for each_txt in file_list:
print(each_txt)
2.获取特定路径下面的所有文件夹
import os
input_dir = r''
file_list = os.listdir(input_dir)
for each_file in file_list:
if os.path.isfile(os.path.join(input_dir,each_file)):
dbtype_list.remove(each_file)
3.获取特定路径下面及其子文件下面的所有文件夹
import glob as glob1
input_file = r'\\'
os.chdir(input_file)
out_put = r'\\'
for item in glob1.iglob('**/*.jp2', recursive=True):
print(item)
name = os.path.basename(item)
file_name = name.split('_')[0] + name.split('_')[1]
out_dir = out_put[:-1] + file_name
if not os.path.exists(out_dir):
os.makedirs(out_dir)
old_file = input_file[:-1] + name
new_file = out_put + name
shutil.copyfile(item, new_file)