当前位置: 首页 > news >正文

中国建设局网站查询沈阳app制作网站建设推

中国建设局网站查询,沈阳app制作网站建设推,小县城做网站,网站建设工程师职责说明windows系统下利用python对指定文件夹下面的所有文件的创建时间进行修改 不知道其他的朋友们有没有这个需求哈#xff0c;反正咱家是有这个需求 需求1、当前有大量的文件需要更改文件生成的时间#xff0c;因为不可告知的原因#xff0c;当前的文件创建时间是不能满足使用的…windows系统下利用python对指定文件夹下面的所有文件的创建时间进行修改 不知道其他的朋友们有没有这个需求哈反正咱家是有这个需求 需求1、当前有大量的文件需要更改文件生成的时间因为不可告知的原因当前的文件创建时间是不能满足使用的 需求2、更改后的时间不能是一样的不能被看出来是文件是一起保存的也就是说看着像是每个文件单独报错的创建时间不一致 看需求只有一个是不是非常的简单但是吧。利用python来实现起来也是非常简单的如果不信的话大家可以跟着小编的文章往下面看哈简单易学一学就会相信小编也是相信自己哈 基础环境 主机版本python版本win10系统python3.8.6 先来看看效果 一看效果大家就知道小编的这个文章是实现的一个什么的功能了 小编这里只是修改了 分钟和秒的时间变得随机了看着就不像是作假的拉当然了代码里面可以进行更改的大家想更改那个时间可以更改那个时间比如改年月日时都可以。小编这里只是提供了一个大概的思路而已,文章最后有完整的代码。 当前有这么的一个文件夹下面有好多的好多的文件当然了小编这边是整理了几个测试专用的文件文件不是很多但是也是把各种格式的文件都是整理了一下 开始运行下代码 查看文件创建时间修改结果 人狠话不多直接开始搞 先import我们需要的几个包 #!/usr/bin/env python # -*- coding: utf-8 -*-import random ###产生随机数的方便咱们文件的创建时间达到不一致的效果 import tkinter as tk ###作用与UI界面的 import os #####作用与当前的额winows系统的比如文件的打开关闭当前的路径等需要这个模块 ###下面的两个就是用来修改时间用的比较关键的 from win32file import CreateFile, SetFileTime, GetFileTime, CloseHandle from win32file import GENERIC_READ, GENERIC_WRITE, OPEN_EXISTING ###下面的都是时间的模块当然了可能有人说为什么使用这么多的模块小编只是懒怎么方便怎么用大家可以研究下减少模块来实现 from pywintypes import Time import time import datetime创建UI操作窗口看起来更逼真 小编的这个窗口还是比较简单的大家可以根据自己的需要定制一个自己的窗口 root tk.Tk() # 创建窗口对象 root.title(指定目录下文件时间批量修改 -----文件辅助程序 v2.10 ) root.geometry(550x300) · · · · 中间内容下面补充 · · · ·# 显示当前进行的操作以及提示 ####会在窗口出现一个白板来显示我们运行的结果 jg tk.LabelFrame(root,text当前进展展示,padx5,pady5) jg.grid(row0,columnspan2,stickyw,padx10,pady10)texttk.Text(jg,width70,height15) scrolltk.Scrollbar(jg) scroll.grid(row0,column1) text.grid(row0,column0) scroll.config(commandtext.yview) text.config(yscrollcommandscroll.set)tk.Button(root, text文件时间修改, width25, commandStart).grid(row1,columnspan2,padx10, pady10) # s南边也就是下边 ###点击文件时间修改按钮会出发Start这个函数接下来我们就补充这个函数root.mainloop() # 进入消息循环 效果 Start函数的编写 def Start():#获取当天日期TIME datetime.datetime.now()定义当前的时间并获取当前的时间:year #当前年份如果有自己的需求这里可以进行更改,eg year2023:month ###当前月如果有自己的需求这里可以进行更改:day ###当前天如果有自己的需求这里可以进行更改:hour ####当前时r如果有自己的需求这里可以进行更改year int(TIME.strftime(%Y))month int(TIME.strftime(%m)) day int(TIME.strftime(%d)) hour int(TIME.strftime(%H)) ####白板展示可以写成一个函数但是小编没写总共用不了几下text.insert(tk.INSERT, \n)text.insert(tk.INSERT, 当前时间已经生成。。。。。。。。)####需要更改文件所在的目录path D:\\wenjian ###根据自己的实际位置进行更改####白板展示text.insert(tk.INSERT, \n)text.insert(tk.INSERT, 正在处理文件请稍等。。。。。。。。)# findfile(path)###批量更改文件时间将year,month,day,hour,path传递给fileChangTime函数执行具体的文件创建日期的修改fileChansTime(year,month,day,hour,path) fileChansTime函数的编写 def fileChansTime(year,month,day,hour,path):####循环path这个文件夹下面的所有文件file_list os.listdir(path)for file_name in file_list:###调用分钟和秒函数来随机生成分钟和秒并赋值minute Minute()second Second()##修改文件创建时间o str(year) - str(month) - str(day) str(hour) : str(minute) : str(second)###小编这里将创建时间、修改时间和访问时间都设置成一样的拉可以根据自己的需要设置成不一样cTime o # 创建时间mTime o # 修改时间aTime o # 访问时间offset (0, 10, 30) # 偏移的秒数# 拼接文件路径文件存在才能成功可以写绝对路径也可以写相对路径小编这里是绝对路径A path \\ file_name# 调用modifyFileTime函数(文章下面有)修改文件创建时间并判断是否修改成功r modifyFileTime(A, cTime, mTime, aTime, offset)if r 0:print(修改完成)text.insert(tk.INSERT, \n)text.insert(tk.INSERT, file_name编辑时间的随机分钟和秒数已经更改成功)elif r 1:text.insert(tk.INSERT, \n)text.insert(tk.INSERT, file_name编辑时间的随机分钟和秒数更改失败请手动更改)分钟和秒的函数的编写 这里可以写成一个函数来达到效果小编这里是写了两个但是不影响效果 如果大家需要更改年月日时的随机值的话可以参照这个办法进行定义一下并在Start函数中进行调用就行 ##取分钟的随机数 def Minute():# 从1到60之间取一个随机数value (random.uniform(1, 60))# .0代表后面的小数位为0个value format(value, .0f)return value##取描述的随机值 def Second():# 从1到60之间取一个随机数value (random.uniform(1, 60))# .0代表后面的小数位为0个value format(value, .0f)return valuemodifyFileTime函数的编写 ##修改文件日期 def modifyFileTime(filePath, createTime, modifyTime, accessTime, offset):用来修改任意文件的相关时间属性时间格式YYYY-MM-DD HH:MM:SS 例如2019-02-02 00:01:02:param filePath: 文件路径名:param createTime: 创建时间:param modifyTime: 修改时间:param accessTime: 访问时间:param offset: 时间偏移的秒数,tuple格式顺序和参数时间对应try:format %Y-%m-%d %H:%M:%S # 时间格式cTime_t timeOffsetAndStruct(createTime, format, offset[0])mTime_t timeOffsetAndStruct(modifyTime, format, offset[1])aTime_t timeOffsetAndStruct(accessTime, format, offset[2])fh CreateFile(filePath, GENERIC_READ | GENERIC_WRITE, 0, None, OPEN_EXISTING, 0, 0)createTimes, accessTimes, modifyTimes GetFileTime(fh)createTimes Time(time.mktime(cTime_t))accessTimes Time(time.mktime(aTime_t))modifyTimes Time(time.mktime(mTime_t))SetFileTime(fh, createTimes, accessTimes, modifyTimes)CloseHandle(fh)return 0except:return 1def timeOffsetAndStruct(times, format, offset):return time.localtime(time.mktime(time.strptime(times, format)) offset)来看看整体的代码效果 #!/usr/bin/env python # -*- coding: utf-8 -*-import random import tkinter as tk import os from win32file import CreateFile, SetFileTime, GetFileTime, CloseHandle from win32file import GENERIC_READ, GENERIC_WRITE, OPEN_EXISTING from pywintypes import Time import time import datetimeroot tk.Tk() # 创建窗口对象 root.title(指定目录下文件时间批量修改 -----文件辅助程序 v2.10 ) root.geometry(550x300)##修改文件日期 def modifyFileTime(filePath, createTime, modifyTime, accessTime, offset):用来修改任意文件的相关时间属性时间格式YYYY-MM-DD HH:MM:SS 例如2019-02-02 00:01:02:param filePath: 文件路径名:param createTime: 创建时间:param modifyTime: 修改时间:param accessTime: 访问时间:param offset: 时间偏移的秒数,tuple格式顺序和参数时间对应try:format %Y-%m-%d %H:%M:%S # 时间格式cTime_t timeOffsetAndStruct(createTime, format, offset[0])mTime_t timeOffsetAndStruct(modifyTime, format, offset[1])aTime_t timeOffsetAndStruct(accessTime, format, offset[2])fh CreateFile(filePath, GENERIC_READ | GENERIC_WRITE, 0, None, OPEN_EXISTING, 0, 0)createTimes, accessTimes, modifyTimes GetFileTime(fh)createTimes Time(time.mktime(cTime_t))accessTimes Time(time.mktime(aTime_t))modifyTimes Time(time.mktime(mTime_t))SetFileTime(fh, createTimes, accessTimes, modifyTimes)CloseHandle(fh)return 0except:return 1def timeOffsetAndStruct(times, format, offset):return time.localtime(time.mktime(time.strptime(times, format)) offset)##取分钟的随机数def Minute():# 从1到60之间取一个随机数value (random.uniform(1, 60))# .0代表后面的小数位为0个value format(value, .0f)return value##取描述的随机值 def Second():# 从1到60之间取一个随机数value (random.uniform(1, 60))# .0代表后面的小数位为0个value format(value, .0f)return valuedef fileChansTime(year,month,day,hour,path):####循环file_list os.listdir(path)for file_name in file_list:print(file_name)minute Minute()second Second()##修改文件创建时间o str(year) - str(month) - str(day) str(hour) : str(minute) : str(second)cTime o # 创建时间mTime o # 修改时间aTime o # 访问时间# 文件路径文件存在才能成功可以写绝对路径也可以写相对路径offset (0, 10, 30) # 偏移的秒数A path \\ file_nameprint(A)# 调用函数修改文件创建时间并判断是否修改成功r modifyFileTime(A, cTime, mTime, aTime, offset)if r 0:print(修改完成)text.insert(tk.INSERT, \n)text.insert(tk.INSERT, file_name编辑时间的随机分钟和秒数已经更改成功)elif r 1:text.insert(tk.INSERT, \n)text.insert(tk.INSERT, file_name编辑时间的随机分钟和秒数更改失败请手动更改)def Start():#获取当天日期TIME datetime.datetime.now()year int(TIME.strftime(%Y)) #当前年份month int(TIME.strftime(%m)) ###当前月day int(TIME.strftime(%d)) ###当前天hour int(TIME.strftime(%H)) ####当前时text.insert(tk.INSERT, \n)text.insert(tk.INSERT, 当前时间已经生成。。。。。。。。)####模板目录path D:\\wenjian####循环文件并进行批量更改text.insert(tk.INSERT, \n)text.insert(tk.INSERT, 正在处理文件请稍等。。。。。。。。)# findfile(path)###批量更改fileChansTime(year,month,day,hour,path)# 显示当前进行的操作以及提示 jg tk.LabelFrame(root,text当前进展展示,padx5,pady5) jg.grid(row0,columnspan2,stickyw,padx10,pady10)texttk.Text(jg,width70,height15) scrolltk.Scrollbar(jg) scroll.grid(row0,column1) text.grid(row0,column0) scroll.config(commandtext.yview) text.config(yscrollcommandscroll.set)tk.Button(root, text文件时间修改, width25, commandStart).grid(row1,columnspan2,padx10, pady10) # s南边也就是下边root.mainloop() # 进入消息循环结束语 工作上终于不是那么忙了以后有时间写自己的博客了自己也是看到需要什么就写什么希望可以帮助到大家再次感谢大家的阅读谢谢。
文章转载自:
http://www.morning.mzhgf.cn.gov.cn.mzhgf.cn
http://www.morning.wmpw.cn.gov.cn.wmpw.cn
http://www.morning.wxccm.cn.gov.cn.wxccm.cn
http://www.morning.mnjyf.cn.gov.cn.mnjyf.cn
http://www.morning.mtbsd.cn.gov.cn.mtbsd.cn
http://www.morning.nwmwp.cn.gov.cn.nwmwp.cn
http://www.morning.qtfss.cn.gov.cn.qtfss.cn
http://www.morning.wwznd.cn.gov.cn.wwznd.cn
http://www.morning.rljr.cn.gov.cn.rljr.cn
http://www.morning.tmnyj.cn.gov.cn.tmnyj.cn
http://www.morning.bhmnp.cn.gov.cn.bhmnp.cn
http://www.morning.nrgdc.cn.gov.cn.nrgdc.cn
http://www.morning.xqxlb.cn.gov.cn.xqxlb.cn
http://www.morning.hilmwmu.cn.gov.cn.hilmwmu.cn
http://www.morning.mlpch.cn.gov.cn.mlpch.cn
http://www.morning.yhdqq.cn.gov.cn.yhdqq.cn
http://www.morning.xiaobaixinyong.cn.gov.cn.xiaobaixinyong.cn
http://www.morning.wgzgr.cn.gov.cn.wgzgr.cn
http://www.morning.rykmf.cn.gov.cn.rykmf.cn
http://www.morning.mrlls.cn.gov.cn.mrlls.cn
http://www.morning.tnrdz.cn.gov.cn.tnrdz.cn
http://www.morning.yzktr.cn.gov.cn.yzktr.cn
http://www.morning.bqqzg.cn.gov.cn.bqqzg.cn
http://www.morning.ffwrq.cn.gov.cn.ffwrq.cn
http://www.morning.ftlgy.cn.gov.cn.ftlgy.cn
http://www.morning.lfcfn.cn.gov.cn.lfcfn.cn
http://www.morning.tmxfn.cn.gov.cn.tmxfn.cn
http://www.morning.brjq.cn.gov.cn.brjq.cn
http://www.morning.fktlg.cn.gov.cn.fktlg.cn
http://www.morning.xlmgq.cn.gov.cn.xlmgq.cn
http://www.morning.nzcgj.cn.gov.cn.nzcgj.cn
http://www.morning.prkdl.cn.gov.cn.prkdl.cn
http://www.morning.sskkf.cn.gov.cn.sskkf.cn
http://www.morning.rzjfn.cn.gov.cn.rzjfn.cn
http://www.morning.rgpbk.cn.gov.cn.rgpbk.cn
http://www.morning.nspbj.cn.gov.cn.nspbj.cn
http://www.morning.wkjzt.cn.gov.cn.wkjzt.cn
http://www.morning.dshxj.cn.gov.cn.dshxj.cn
http://www.morning.jlnlr.cn.gov.cn.jlnlr.cn
http://www.morning.pkrb.cn.gov.cn.pkrb.cn
http://www.morning.jqbpn.cn.gov.cn.jqbpn.cn
http://www.morning.jspnx.cn.gov.cn.jspnx.cn
http://www.morning.yhpq.cn.gov.cn.yhpq.cn
http://www.morning.gkdhf.cn.gov.cn.gkdhf.cn
http://www.morning.wyfpc.cn.gov.cn.wyfpc.cn
http://www.morning.dtnzk.cn.gov.cn.dtnzk.cn
http://www.morning.mnkhk.cn.gov.cn.mnkhk.cn
http://www.morning.xjbtb.cn.gov.cn.xjbtb.cn
http://www.morning.cpnsh.cn.gov.cn.cpnsh.cn
http://www.morning.pcgjj.cn.gov.cn.pcgjj.cn
http://www.morning.zlff.cn.gov.cn.zlff.cn
http://www.morning.nrydm.cn.gov.cn.nrydm.cn
http://www.morning.ysqb.cn.gov.cn.ysqb.cn
http://www.morning.smpmn.cn.gov.cn.smpmn.cn
http://www.morning.txqgd.cn.gov.cn.txqgd.cn
http://www.morning.mczjq.cn.gov.cn.mczjq.cn
http://www.morning.wgqtt.cn.gov.cn.wgqtt.cn
http://www.morning.jbysr.cn.gov.cn.jbysr.cn
http://www.morning.fksrg.cn.gov.cn.fksrg.cn
http://www.morning.dhqzc.cn.gov.cn.dhqzc.cn
http://www.morning.pslzp.cn.gov.cn.pslzp.cn
http://www.morning.fpjxs.cn.gov.cn.fpjxs.cn
http://www.morning.jypqx.cn.gov.cn.jypqx.cn
http://www.morning.hwsgk.cn.gov.cn.hwsgk.cn
http://www.morning.ktlfb.cn.gov.cn.ktlfb.cn
http://www.morning.gfnsh.cn.gov.cn.gfnsh.cn
http://www.morning.mrfgy.cn.gov.cn.mrfgy.cn
http://www.morning.nfks.cn.gov.cn.nfks.cn
http://www.morning.prysb.cn.gov.cn.prysb.cn
http://www.morning.kgltb.cn.gov.cn.kgltb.cn
http://www.morning.jpmcb.cn.gov.cn.jpmcb.cn
http://www.morning.ndlww.cn.gov.cn.ndlww.cn
http://www.morning.fksyq.cn.gov.cn.fksyq.cn
http://www.morning.clndl.cn.gov.cn.clndl.cn
http://www.morning.zhishizf.cn.gov.cn.zhishizf.cn
http://www.morning.ghlyy.cn.gov.cn.ghlyy.cn
http://www.morning.pmtky.cn.gov.cn.pmtky.cn
http://www.morning.kqpq.cn.gov.cn.kqpq.cn
http://www.morning.bsjpd.cn.gov.cn.bsjpd.cn
http://www.morning.zgpgl.cn.gov.cn.zgpgl.cn
http://www.tj-hxxt.cn/news/242653.html

相关文章:

  • 黔南州建设局网站wordpress图片备用地址
  • 建设网站建设方案网站微信建设
  • 电子商务网站开发这书不出版了吗网上国网推广
  • 网站建设工期安排表公众号开发者密码是什么意思
  • 家具设计师常去的网站电子商务是干嘛的 主要学什么
  • 网站内容页面怎么做我的电脑做网站服务器吗
  • 建设网站需要购买九江市房管局建设官方网站
  • 昆明网站优化建设银行佛山分行网站
  • 西安手机网站开发电子商务网站设计流程
  • 金华网站建设公司织梦移动网站后缀
  • 福建网站建设费用宁波seo快速优化技术
  • 旅游网站名字淘客网站系统免费源码
  • 做排行榜的网站知乎WordPress生成分享图片
  • 高端网站制作乐是百度注册公司网站
  • wordpress 相册 免费模板百度seo排名如何提升
  • 金融理财网站建设成免费的crm
  • 网站注册界面软件开发 东莞
  • kuake自助建站系统官网房地产网站模板
  • 新郑郑州网站建设建设写小说网站
  • 温州网站建设技术托管如何做好电商销售
  • 手机网站底部导航菜单网站的头尾和导航的公用文件
  • 做搜狐网站页面做地方网站赚钱吗
  • wordpress做复杂网站网站建设多少钱十年乐云seo
  • 如何利用视频网站做推广建设机械网站哪家好
  • 网站建设柒金手指下拉二一运城网站建设公司
  • 新西兰网站开发专业定制网站开发报价单
  • 的建站公司中小型门户网站
  • 现在门户网站建设还有人弄吗做网站栏目都包括什么
  • 网站页面设计与制作实践盱眙县建设局网站
  • 网站打开出现建设中道滘镇仿做网站