티스토리 뷰

SWDesk

[Python] Backup Files

inhae 2022. 7. 10. 20:29

디렉토리 확인/생성, 파일 복사

 

def Test_FileTransfer():
    import shutil
    sourceFolder = "./Reports"
    destFolder = "N:/DevData/MBIData/Reports"
    subFolderList = []

    sourceFileList = os.listdir(sourceFolder)
    destFileList = os.listdir(destFolder)
    for file1 in sourceFileList:
        file2 = destFolder + "/"+file1
        if os.path.isdir(file1):
            subFolderList.append(file1)
            continue
        if os.path.exists(file2):
            continue
        file12 = sourceFolder + "/" + file1
        shutil.copy(file12, file2)
    folderTransferred = {}
    while True:
        isAllTranserred = True
        print("[Size of SubFolderList]", len(subFolderList))
        for subFolder1 in subFolderList:
            isTransferred = folderTransferred.get(subFolder1)
            if isTransferred: contine;
            sourceFileList = os.listdir(subFolder1)
            #destFileList = os.listdir(destFolder)
            for file1 in sourceFileList:
                file2 = destFolder + "/"+ subFolder1 + "/" + file1
                if os.path.isdir(file1):
                    file11 = subFolder1 + "/" + file1
                    isAllTransferred = False
                    subFolderList.append(file11)
                    continue
                if os.path.exists(file2):
                    continue
                file12 = sourceFolder + "/" + subFolder1 + "/" + file1
                shutil.copy(file12, file2)
            folderTransferred[subFolder1] = True
        if isAllTranserred: break;

 

 

 

 

반응형
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함