import os
import os.path
rootdir = "./pic_data"
file_object = open('train_list.txt','w')
for parent,dirnames,filenames in os.walk(rootdir):
for filename in filenames:
print filename
file_object.write(filename+ '\n')
file_object.close()
在做深度学习的时候,会有大量的数据,为了方便,可以直接用命令拷贝到一个文件夹下,代码如下:
import shutil
import os
import os.path
rootdir = "./mjsynth/mnt/ramdisk/max/90kDICT32px"
def Test2(rootDir):
for lists in os.listdir(rootDir):
if lists[-3:]=='jpg':
print lists
path = os.path.join(rootDir, lists)
shutil.copy(path,"./500")
continue
if int(lists)<501:
path = os.path.join(rootDir, lists)
if os.path.isdir(path):
Test2(path)
Test2(rootdir)