简体   繁体   中英

Moving large files using shutil.move

I have written a code for moving files from one folder to another .I moved only those files whose names are present in my text file(aiq.txt). It works fine when files are less in number say(10) but when number goes to around 500 the program terminates. Each file is of 50 Mb Here is my code:

import os
import shutil
destination=r"dstpath"
with open("aiq.txt") as infile:
    for line in infile:
        line=line.strip('\n)
        for root,dirs,filenames in os.walk(r"H:\test_vectors"):
            for filename in filenames:
                if line in filename:
                    shutil.move(os.path.join(root,filename),destination)
import os
import shutil

root = r"H:\test_vectors"
destination = r"dstpath"

file_list = []
dir_dict = {}

with open('aiq.txt', 'r') as f:
    for line in f:
        file_list.append(line.strip())

for d, dirs, files in os.walk(root):
    if files:
        dir_dict[d] = files

for key, item in dir_dict.items():
    for x in item:
        if x in file_list:
              try:
                  shutil.move(os.path.join(key, x), destination)
              except:
                  pass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM