Skip to content

Instantly share code, notes, and snippets.

@glamourzc
Created January 6, 2019 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glamourzc/2d99cba564c1b0304e27c66567463e0f to your computer and use it in GitHub Desktop.
Save glamourzc/2d99cba564c1b0304e27c66567463e0f to your computer and use it in GitHub Desktop.
使用python遍历文件夹复制文件
import os
import os.path
import shutil
finalPos = open("J:/SourcesDataSet/Pos.txt",'w')
for root,dirs,files in os.walk("J:/SourcesDataSet/"):
if 'Pos.txt' in files:
pos = open(root+'/Pos.txt','r')
temp = pos.readlines()
finalPos.writelines(temp)
pos.close()
for i in files:
if os.path.splitext(i)[1] == '.bmp':
shutil.copy(root+'/'+i,'J:/SourcesDataSet')
finalPos.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment