简体   繁体   English

如何只复制python3文件夹中的文件?

[英]How to copy just the files in a folder in python3?

        source = ('C:\\Qualys Report\\Qualys Data\\')
        dest1 = ('C:\\Qualys Report\\Backup\\')           
        for filename in os.listdir(source):
            if filename.endswith('.csv'):
                shutil.move(source+filename, dest1)

For some reason its moving the folder and csv file i have into the backup folder 由于某种原因,我将文件夹和csv文件移到了备份文件夹中

Anyway i can just move the file itself? 无论如何,我只能移动文件本身?

From the question it seems you are simply trying to copy the csv files from a single source dir (not recursively), you should use copy not move/rename if you wish to keep the original copy in place, with a copy in dest1. 从这个问题看来,您似乎只是在尝试从单个源目录复制csv文件(而不是递归地),如果希望保留原始副本并在dest1中保留副本,则应使用copy not move / rename。

    import os
    source = ('C:\\Qualys Report\\Qualys Data\\')
    dest1 = ('C:\\Qualys Report\\Backup\\')

    for filename in os.listdir(source):
        if filename.endswith('.csv'):
            shutil.copy(source+filename, dest1)

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

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