python - Reading a text file and moving files from it to a directory -
i have directory of images. of these images must stored in text file 'pic1.jpg'
i need extract filename, pick matching file current working directory , move separate folder (under cwd).
this code have far, cant shutil operations work. doing wrong?
current directory c:\be
have move file(s) 1,jpg, 2,jpg etc textfile called "filelist.txt" c:\be\2014-03-25_02-49-11
import os, datetime import shutil src = os.getcwd() global mydir def filecreation(content, filename): mydir = os.path.join(os.getcwd(), datetime.datetime.now().strftime('%y-%m-%d_%h-%m-%s')) try: os.makedirs(mydir) except oserror, e: if e.errno != 17: raise # not "directory exist" error.. open(os.path.join(mydir, filename), 'w') d: d.writelines(content) #shutil.copyfile(src,mydir) def main(): filelist = "filelist.txt" open(filelist) f: content = f.read().splitlines() #content = shutil.copyfile(src, mydir) print content print "here are" #list=['1.jpg','2.jpg'] filecreation(content,"filelist.txt") print "lets try method" open('filelist.txt','w+') list_f: filename in list_f: open(filename) f: content = f.read() #content = shutil.move(src,mydir) #content = shutil.copyfile(src,mydir) #for line in f print "method 2 working far" if __name__ == '__main__': main()
this worked -
from shutil import copy f = open(r'c:\users\b\desktop\be project\k\filelist.txt', 'r') in f.readlines(): print copy(i.strip(),r"e:\images") f.close()
Comments
Post a Comment