Python. IOError: [Errno 13] Permission denied: when i'm copying file

后端 未结 9 1390
轮回少年
轮回少年 2021-01-03 19:44

I have two folders: In, Out - it is not system folder on disk D: - Windows 7. Out contain \"myfile.txt\" I run the following command in python:

>>>          


        
9条回答
  •  难免孤独
    2021-01-03 20:03

    This works for me:

    import os
    import shutil
    import random
    
    
    dir = r'E:/up/2000_img'
    output_dir = r'E:/train_test_split/out_dir'
    
    
    files = [file for file in os.listdir(dir) if os.path.isfile(os.path.join(dir, file))]
    
    if len(files) < 200:
        # for file in files:
        #     shutil.copyfile(os.path.join(dir, file), dst)
        pass
    else:
        # Amount of random files you'd like to select
        random_amount = 10
        for x in range(random_amount):
            if len(files) == 0:
                break
            else:
                file = random.choice(files)
                shutil.copyfile(os.path.join(dir, file), os.path.join(output_dir, file))
    

提交回复
热议问题