批处理指令

版权声明:坚持原创,禁止转载。 https://blog.csdn.net/SLAM_masterFei/article/details/80416237

最近想做深度学习,如果数据量大的话那就需要批处理指令来完成了,具体做法windows

就是在你的文件夹下新建一个txt文件,放入

DIR *.*  /B >LIST.TXT

然后改格式为bat,然后双击,就出现了list.txt格式的文件,里面有这个文件夹所以的名称

如果是linux,需要建立一个脚本文件复制内容如下

file=test.txt
path=train

find $path -name *.jpg > $file


sed -i 's/$/ 1/g' $file

最后一行表示我们在每个文件最后用空格和1来替换文本的末尾,其实就是加上这些。。。

find 就是在当前路径下找到所以jpg的文件并写入txt文件

如果想要python修改杂乱无章的图片名字,可以:

# -*- coding:utf8 -*-

import os

class BatchRename():
    '''
    批量重命名文件夹中的图片文件

    '''
    def __init__(self):
        self.path = '/home/f/Downloads/test/cat'

    def rename(self):
        filelist = os.listdir(self.path)
        total_num = len(filelist)
        i = 0
        for item in filelist:
            if item.endswith('.jpg'):
                src = os.path.join(os.path.abspath(self.path), item)
                dst = os.path.join(os.path.abspath(self.path), str(i) + '.jpg')
                try:
                    os.rename(src, dst)
                    print 'converting %s to %s ...' % (src, dst)
                    i = i + 1
                except:
                    continue
        print 'total %d to rename & converted %d jpgs' % (total_num, i)

if __name__ == '__main__':
    demo = BatchRename()
    demo.rename()

猜你喜欢

转载自blog.csdn.net/SLAM_masterFei/article/details/80416237