文件夹重命名

import os,time

path = r"D:\重命名图片"

# files =  os.listdir(path)list_url = ["Mainpage","New Products All products(Most Popular)","New Products All products(Featured)","New Products All products(Most Recent)","New Products Dresses(Most Popular)","New Products Dresses(Featured)","New Products Dresses(Most Recent)","New Products Bottoms(Most Popular)","New Products Bottoms(Featured)","New Products Bottoms(Most Recent)","New Products Outwear(Most Popular)","New Products Outwear(Featured)","New Products Outwear(Most Recent)","New Products Rompers Jumpsuits(Most Popular)","New Products Rompers Jumpsuits(Featured)","New Products Rompers Jumpsuits(Most Recent)","New Products Swim(Most Popular)","New Products Swim(Featured)","New Products Swim(Most Recent)","New Products Tops(Most Popular)","New Products Tops(Featured)","New Products Tops(Most Recent)","Back In Stock All products(Most Popular)","Back In Stock All products(Featured)","Back In Stock All products(Most Recent)","Back In Stock Dresses(Most Popular)","Back In Stock Dresses(Featured)","Back In Stock Dresses(Most Recent)","Back In Stock Bottoms(Most Popular)","Back In Stock Bottoms(Featured)","Back In Stock Bottoms(Most Recent)","Back In Stock Outwear(Most Popular)","Back In Stock Outwear(Featured)","Back In Stock Outwear(Most Recent)","Back In Stock Rompers Jumpsuits(Most Popular)","Back In Stock Rompers Jumpsuits(Featured)","Back In Stock Rompers Jumpsuits(Most Recent)","Back In Stock Swim(Most Popular)","Back In Stock Swim(Featured)","Back In Stock Swim(Most Recent)","Back In Stock Tops(Most Popular)","Back In Stock Tops(Featured)","Back In Stock Tops(Most Recent)","Top Rated All products(Most Popular)","Top Rated All products(Featured)","Top Rated All products(Most Recent)","Top Rated All products(Top Rated)","Top Rated Dresses(Most Popular)","Top Rated Dresses(Featured)","Top Rated Dresses(Most Recent)","Top Rated Dresses(Top Rated)","Top Rated Bottoms(Most Popular)","Top Rated Bottoms(Featured)","Top Rated Bottoms(Most Recent)","Top Rated Bottoms(Top Rated)","Top Rated Outwear(Most Popular)","Top Rated Outwear(Featured)","Top Rated Outwear(Most Recent)","Top Rated Outwear(Top Rated)","Top Rated Rompers Jumpsuits(Most Popular)","Top Rated Rompers Jumpsuits(Featured)","Top Rated Rompers Jumpsuits(Most Recent)","Top Rated Rompers Jumpsuits(Top Rated)","Top Rated Swim(Most Popular)","Top Rated Swim(Featured)","Top Rated Swim(Most Recent)","Top Rated Swim(Top Rated)","Top Rated Tops(Most Popular)","Top Rated Tops(Featured)","Top Rated Tops(Most Recent)","Top Rated Tops(Top Rated)","All Dress Most Popular","All Dress Featured","All Dress Most Recent","All Dress Top Rated","Formal Dress Most Popular","Formal Dress Featured","Formal Dress Most Recent","Formal Dress Top Rated","Clothing Tops(Most Popular)","Clothing Tops(Featured)","Clothing Tops(Most Recent)","Clothing Tops(Top Rated)","Clothing Bottoms(Most Popular)","Clothing Bottoms(Featured)","Clothing Bottoms(Most Recent)","Clothing Bottoms(Top Rated)","Clothing Rompers Jumpsuits(Most Popular)","Clothing Rompers Jumpsuits(Featured)","Clothing Rompers Jumpsuits(Most Recent)","Clothing Rompers Jumpsuits(Top Rated)","Clothing Demin(Most Popular)","Clothing Demin(Featured)","Clothing Demin(Most Recent)","Clothing Demin(Top Rated)","Clothing Two Piece Sets(Most Popular)","Clothing Two Piece Sets(Featured)","Clothing Two Piece Sets(Most Recent)","Clothing Two Piece Sets(Top Rated)","Clothing Outwear(Most Popular)","Clothing Outwear(Featured)","Clothing Outwear(Most Recent)","Clothing Outwear(Top Rated)","Clothing Knitwear(Most Popular)","Clothing Knitwear(Featured)","Clothing Knitwear(Most Recent)","Clothing Knitwear(Top Rated)","Clothing Office-chic(Most Popular)","Clothing Office-chic(Featured)","Clothing Office-chic(Most Recent)","Clothing Office-chic(Top Rated)","Clothing Loungewear(Most Popular)","Clothing Loungewear(Featured)","Clothing Loungewear(Most Recent)",]

def get_file_list(file_path):    """文件按时间排序,从小到大排序"""    dir_list = os.listdir(file_path)    if not dir_list:        return    else:        # 注意,这里使用lambda表达式,将文件按照最后修改时间顺序升序排列        dir_list = sorted(dir_list,key=lambda x: os.path.getmtime(os.path.join(file_path, x)))        return dir_list

print(get_file_list( r"D:\重命名图片"))files = get_file_list(r"D:\重命名图片")print(files)# 获取文件修改时间# for i in range(len(files)):#     file_time = time.localtime(os.stat(r"D:\重命名图片\{}" .format(files[i])).st_mtime)##     print("{}的打印时间是:" .format(files[i]),time.strftime("%Y-%m-%d %H:%M:%S",file_time))

for f in range(len(files)):    """按照时间顺序,修改文件名称"""    #调试代码的方法:关键地方打上print语句,判断这一步是不是执行成功    print(f)    if "screencapture" in files[f] and files[f].endswith(".png") or files[f].endswith(".jpg"):        print("原来的文件名字是:{}".format(files[f]))        #找到老的文件所在的位置        old_file=os.path.join(path,files[f])        print("old_file is {}".format(old_file))        #指定新文件的位置,如果没有使用这个方法,则新文件名生成在本项目的目录中        new_file=os.path.join(path,‘{}.png‘ .format(list_url[f]) )        print("File will be renamed as:{}".format(new_file))        os.rename(old_file,new_file)        print("修改后的文件名是:{}".format(files[f]))

print(len(list_url))import timeimport datetime

# import os## file_time = time.localtime(os.stat(r"D:\重命名图片\首页.png").st_mtime)# print(file_time)# print(time.strftime("%Y-%m-%d %H:%M:%S",file_time))

原文地址:https://www.cnblogs.com/nieliangcai/p/12322985.html

时间: 2024-11-07 13:04:52

文件夹重命名的相关文章

iOS 创建文件夹,删除文件夹,对文件夹重命名的操作

iOS 创建文件夹,删除文件夹,对文件夹重命名的操作 by 伍雪颖 + (void)createFolder:(NSString *)folderName { NSString *imageDir = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(),folderName]; NSLog(@"HomeDir: %@",imageDir); BOOL isDir = NO; NSFileM

IntelliJ IDEA 文件夹重命名--解决重命名后js文件引用找不到路径报404错误

情景: 说明:ExtJS是我后来的改的名字--原来叫extjs,可是当我把在页面的引用地址改为 src="ExtJS/.."后页面就报404错误,我把它改回之前的extjs就可以(像上面的一样),这个小问题真心烦,百度也没有. 后来 我又改个名字,这时候留意了: 上面红框的选项勾选就可以了.

php文件夹下文件批量重命名

php文件夹下文件批量重命名 <?php header("Content-type:text/html;charset=utf-8"); $dir = __DIR__.'./color/'; $file_arr = scandir($dir); unset($file_arr[0]); unset($file_arr[1]); $file_arr = array_values($file_arr); $n = count($file_arr); for ($i = 0; $i &

C#实现文件批量重命名源码下载

本文要实现的功能是 文件批量重命名,当选择一个文件夹时,通过操作可以把文件夹下面所有文件进行重命名.建立了HoverTreeBatch项目. 然后 定义文件夹信息: DirectoryInfo _TheFolder; //这里是选择文件夹并实例化_TheFolder FileInfo[] _files=null; _files = _TheFolder.GetFiles(); 这样就得到了文件夹下所有文件信息. //加后缀 foreach (FileInfo fi in _files) { Ho

利用php实现文件迁移重命名

首先表明,这是一个悲伤的故事. 暑假来临,学校安排我们到某软件外包公司实习,想想不用面试也是蛮方便的,可以借此机会向大牛学习学习,虽然没有工资(据说学校还交了600块的保险),但想想还是蛮期待的,但真正到公司就懵逼了~技术人员都不在好不好!职位都安排好了,什么人力资源,经营管理,还有财务管理之类,做培训的,但没有一个写代码的啊! 我被分到了经营管理部门,每天接触的是各种合同审批,合同扫描,合同盖章,合同...  总之围着合同团团转,打杂远远多于学习.想想如果没有我们那些公司的人也要处理如此重复无

Linux查找多个类似但是不同名的文件并且重命名

这个题目据说是百度一面的面试题,Linux题:查找以core.1,core.2....形式命名的文件,然后将这些文件名改成bak.core.1,bak.core.2,...... 首先应该找到这些文件,使用 find . -name "core.[0-9]" -print   ,可以找到: find的使用方法: 1.命令格式: find pathname -options [-print -exec -ok ...] 2.命令功能: 用于在文件树种查找文件,并作出相应的处理 3.命令参

用nodeJs实现文件夹内所有文件的重命名

nodeJs中我比较感兴趣的有一个地方就是fs文件系统. 今天就用nodeJs实现了一个重命名文件夹内所有文件的脚本. 命名可以自定义. 'use strict';var fs = require('fs');var i = 0;var $ = "$";//setting areavar directory = './files';var format = 'test'+$;//setting areafunction rename(fileName,formation){ fs.re

使用java对文件批量重命名

有时候从网络上下载的电视剧或者动漫,名字上都会被该网站加上前缀或者后缀,如图: 那么处女座的同学就不同意了,不行,我就是想让它按照我的习惯方式命名!但是呢,一个个修改是不是特别麻烦,如果是上百个呢?如果上千个呢?改到手抽筋都改不完啊!闲来没事写了个小程序,用来对这样统一格式的文件进行批量重命名,当然,必须是这种统一格式的命名方式,如上图所显示的那样,废话不多说,直接贴代码,简单易懂,无甚可将! public class CHBRenamer { public static void main(S

python实现对文件批量重命名(用到正则表达式和os.path模块)

# 成功实现批量文件重命名# 具体是批量截取了部分有用的数据用来重命名# 用到了正则表达式 import osimport os.pathimport re path = 'C:/Users/Administrator/Desktop/新建文件夹 (2)/讲义' #注意必须是正斜杠/,反斜杠\在python是转义字符 # 三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for parent, dirnames, filenames in os.walk(path)