# !/usr/bin/env python
# coding=utf-8
import os
def scan_files(directory, prefix=None, postfix=".mid"):
files_list = []
for root, sub_dirs, files in os.walk(directory):
for special_file in files:
if postfix:
if special_file.endswith(postfix):
files_list.append(os.path.join(root, special_file))
elif prefix:
if special_file.startswith(prefix):
files_list.append(os.path.join(root, special_file))
else:
files_list.append(os.path.join(root, special_file))
return files_list
def copy_file_list_to_file(file_list,file):
for i in file_list:
with open(i,"rb") as f:
data=f.read()
with open(file+"/"+i.replace("\\","").replace("'","")[3:],"wb") as p:
p.write(data)
if __name__ == '__main__':
file_name = "D:/MIDI_train"
file_list=scan_files(directory=file_name)
copy_file_list_to_file(file_list, "D:/MIDI_m")
python 扫描(可以按照后缀前缀扫描)并复制到另一个文件夹中
猜你喜欢
转载自blog.csdn.net/weixin_32759777/article/details/123661097
今日推荐
周排行