Python automatically copies N png/jpg/jpeg files in the current file directory

Python automatically copies N png/jpg/jpeg files in the current file directory

 

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 memory-mapped file read and write_python file mapping_zhangphil's blog-CSDN blog import osimport timeimport mmapfilename = 'test.txt' #If it does not exist, create it. 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

Formatted random row data is written to a local file, Python_python formatted and written to a file_zhangphil's blog-CSDN blog Formatted random row data is written to a local file, Python https://blog.csdn.net/zhangphil/article/ details/125226462

 

Guess you like

Origin blog.csdn.net/zhangphil/article/details/130264996