简体   繁体   English

将n个文件复制到另一个文件夹的Python脚本

[英]Python script to copy n files to another folder

I'm looking for a python script that would took for example first 5000 files and copy them to another folder.我正在寻找一个 python 脚本,它可以获取前 5000 个文件并将它们复制到另一个文件夹。 Then after another run, it would took next 5000 files and copy them.然后再运行一次,它需要接下来的 5000 个文件并复制它们。

I tried using shutil but couldn't make it work, no matter what I tried.我尝试使用shutil但无论我尝试什么都无法使其工作。

Can you please help, or guide me on the right direction?你能帮忙,或指导我正确的方向吗?

What you may be looking for is a combination of os.walk() HERE and shutil.copy() HERE您可能正在寻找的是 os.walk() HERE和 shutil.copy() HERE 的组合

Building a script based on sample provided on those two links looks pretty straight forward.根据这两个链接上提供的示例构建脚本看起来非常简单。

Good luck.祝你好运。

This should do it for you read the code for help to make it work Change the Mkv format to whatever you want这应该为您阅读代码以帮助使其工作将 Mkv 格式更改为您想要的任何格式

it's a python script you can use crontab for Linux or Microsoft windows schedule tool if you need any help just reply这是一个 python 脚本,如果您需要任何帮助,您可以将 crontab 用于 Linux 或 Microsoft Windows 计划工具,请回复

import os
import json

SRC_FOLDER = '/home/SOURCE /'
DEST_FOLDER = '/home/Destination folder /'

def read_data():
    with open('/home/PATH TO the json file.json') as f:
        data = json.load(f)
        return data

def write_data(added_files, uploaded_files):
    with open('/home/PATH TO the json file.json', 'w') as f:
        json.dump(added_files+uploaded_files, f)

def main():
    all_downloads = os.listdir(SRC_FOLDER)
    all_uploads = read_data()
    added_files = []
    for file_name in all_downloads:
        if file_name not in all_uploads:
            if "mkv" == file_name.split(".")[-1]:
                print file_name.split('.')[-1]
                added_files.append(file_name)
                file = open(DEST_FOLDER+file_name, 'wb')
                with open(SRC_FOLDER+file_name, 'rb') as f:
                    while True:
                        byte = f.read(20480)
                        if not byte:
                            break
                        file.write(byte)
    write_data(added_files, all_uploads)

if __name__ == '__main__':
    main()

iCODEiT 0UT iCODEiT 0UT

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Linux 在 bash/python 脚本中将下一个“n”个文件从一个文件夹复制到另一个文件夹 - Linux copy next 'n' number of files from one folder to another in bash/python script python 或任何其他脚本来查找文件并将它们复制到另一个文件夹中 - python or any other script to find files and copy them into another folder 使用python脚本将一个文件夹中的多个jpeg文件和json文件复制并排序到子文件夹文件夹中的另一个文件夹 - copy and sort multiple jpeg files and json files in one folder to another folder in subfolders folder using python script 将文件复制到另一个文件夹,避免在 python 中重复 - copy files to another folder, avoiding duplication in python 使用python将文件复制到另一个文件夹 - Copy files to another folder using python python脚本在特定时间间隔后连续轮询文件夹并将新文件复制到另一个位置 - python script to poll a folder continuously after a certain time interval and copy the new files to another location 我正在编写python脚本,通过在一行中给出输入值,将图像文件(.jpg)从一个文件夹复制到另一个文件夹 - I am writing the python script for copy the image files (.jpg)from one folder to another folder by giving inputs values in one line Python将文件复制到文件夹 - Python copy files to folder 如何将从 txt 文件中选择的文件复制到另一个文件夹 python - How to copy files selected from a txt file to another folder python 使用 python 在 AWS S3 上将文件从一个文件夹复制到另一个文件夹 - copy files from one folder to another on AWS S3 with python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM