티스토리 뷰

File, Directory, move, rename

파일, 디렉토리, 이동, 복사

import os
import shutil
from cBExcel import cBExcel
from pandas import DataFrame

sourcePath = "I:/Readables"
sourceFoldername = "OnlineShop"
sourceFolderPath = sourcePath+"/"+sourceFoldername
destPath = "I:/Readables/OnlineShop218"
destTitle = "OnlineShop"
excelFilename = "OnlineShop218.xlsx"
stopWord = "y2mate.com - "

fileList = os.listdir(sourcePath+"/"+sourceFoldername)
print(fileList)
os.mkdir(destPath)
excel1 = cBExcel()

count1 = 0
fileList_DF = DataFrame()
for fileName1 in fileList:
    count1 += 1
    ext1 = os.path.splitext(fileName1)[-1]
    fileName2 = fileName1.replace(",", "-")
    fileName3 = fileName2.replace(stopWord, "")
    destFilename = destTitle+"{0:03d}".format(count1)+ext1
    destFilePathname = destPath + "/"+destFilename
    shutil.move(sourceFolderPath+"/"+fileName1, destFilePathname)
    fileInfo1 = {
        'OriginalFilename': fileName3,
        'RenamedTo': destFilename
    }

    print(fileInfo1)

    if fileList_DF.empty:
        fileList_DF = DataFrame([fileInfo1])
    else:
        fileList_DF = fileList_DF.append(fileInfo1, ignore_index=True)
if not fileList_DF.empty:
    excel1 = cBExcel()
    excelPathname = sourcePath+"/"+excelFilename
    excel1.SaveData(fileList_DF, excelPathname)

<참조 링크 페이지>

01_파일, 디렉터리 관리하기 - 핵심만 간단히, Hello World! 파이썬 3.pdf
0.31MB

반응형

'SWDesk' 카테고리의 다른 글

[Python] 최근 신규 키워드 찾아서 표시하기  (2) 2021.08.27
[Python] datetime 예제  (0) 2021.08.24
[Python] Archiving in ZIP  (0) 2021.08.14
[Python] Dataframe to Dict  (1) 2021.08.08
인공지능 스타트업  (0) 2021.07.17