Python は、現在のファイル ディレクトリに N 個の png/jpg/jpeg ファイルを自動的にコピーします。

Python は、現在のファイル ディレクトリに N 個の png/jpg/jpeg ファイルを自動的にコピーします。

 

import os
import shutil
import time

PNG = 'png'
JPG = 'jpg'
JPEG = 'jpeg'

COUNT = 5  # 复制的数量


# 获取当前文件目录下原始源文件的前缀和后缀
def get_file_info():
    for root, dirs, files in os.walk(".", topdown=False):
        for name in files:
            if (name.endswith(PNG) or name.endswith(JPG) or name.endswith(JPEG)):
                pre = name.split('.')[0]
                suf = name.split('.')[1]
                print('pre:' + pre + " suf:" + suf)
                return name, pre, suf


if __name__ == '__main__':
    fn, pre, suf = get_file_info()
    for i in range(COUNT):  # 复制的数量
        time.sleep(0.1)
        shutil.copyfile(fn, '{pre}-{i}.{suf}'.format(pre=pre, i=i, suf=suf))

 

 

 

Python メモリ マップド ファイルの読み取りと書き込み_python ファイル マッピング_zhangphil のブログ - CSDN ブログimport osimport timeimport mmapfilename = 'test.txt' #存在しない場合は作成します。if not os.path.exists(filename): open(filename, 'w')print(os.path.isdir(filename))if os.path.isfile(filename): print(ti... https:// blog.csdn.net/zhangphil/article/details/88691321

フォーマットされたランダム行データがローカル ファイルに書き込まれます、Python_python フォーマットされてファイルに書き込まれます_zhangphil のブログ - CSDN ブログ フォーマットされたランダム行データがローカル ファイルに書き込まれます、Python https://blog.csdn.net/zhangphil/article/ details/ 125226462

 

おすすめ

転載: blog.csdn.net/zhangphil/article/details/130264996