第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

os.walk()應(yīng)用于訂單程序

os.walk()應(yīng)用于訂單程序

Smart貓小萌 2023-12-29 10:33:02
我想在我的具體情況下使用 walk.os,因?yàn)闀r(shí)間到了,我訂購(gòu)了一些圖像。這些圖像位于文件夾“D:/TR/Eumetsat_IR_photos/Prueba”中,我的想法是從“D:/TR/Eumetsat_IR_photos”中包含的不同文件夾中獲取所有圖像,將它們排序到兩個(gè)名為“白天”和“夜間”的特定文件夾中。我不知道如何調(diào)整程序以使用這個(gè) os.walk()這并不重要,但是圖像的時(shí)間出現(xiàn)在第 37 和 39 位的所有圖像名稱中(這樣你就可以正確理解它)。謝謝from os import listdir, path, mkdirimport shutildirectorio_origen = "D:/TR/Eumetsat_IR_photos/Prueba"directorio_destino_dia = "D:/TR/IR_Photos/Daytime"directorio_destino_noche = "D:/TR/IR_Photos/Nighttime"def get_hour(file_name):    return file_name[37:39]for fn in list0:    hora = int(get_hour(fn))    file_directorio= directorio_origen+"/"+fn    if 6 < hora < 19:         new_directorio= directorio_destino_dia    else:        new_directorio= directorio_destino_noche            try:        if not path.exists(new_directorio):            mkdir(new_directorio)        shutil.copy(file_directorio, new_directorio)    except OSError:        print("el archivo %s no se ha ordenado" % fn)
查看完整描述

1 回答

?
幕布斯7119047

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊

通過(guò)對(duì)代碼進(jìn)行一些修改,類似這樣的事情就可以做到:


import shutil

import os


directorio_origen = "D:/TR/Eumetsat_IR_photos/Prueba"

directorio_destino_dia = "D:/TR/IR_Photos/Daytime"

directorio_destino_noche = "D:/TR/IR_Photos/Nighttime"


def get_hour(file_name):

    return file_name[37:39]


for root, dirs, files in os.walk(directorio_origen, topdown=False):

    for fn in files:

        path_to_file = os.path.join(root, fn)

        hora = int(get_hour(fn))

        new_directorio = ''

        if 6 < hora < 19: 

            new_directorio= directorio_destino_dia

        else:

            new_directorio= directorio_destino_noche

        try:

            if not os.path.exists(new_directorio):

                os.mkdir(new_directorio)

            shutil.copy(path_to_file, new_directorio)

        except OSError:

            print("el archivo %s no se ha ordenado" % fn)


查看完整回答
反對(duì) 回復(fù) 2023-12-29
  • 1 回答
  • 0 關(guān)注
  • 143 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)