首页 > 其他分享 >tool_watch_file

tool_watch_file

时间:2023-05-30 15:55:25浏览次数:31  
标签:files tool time watch current file path watched

import os
import shutil
import time

watched_path = '/data/tmp/'
#watched_path = '/tmp/'
target_dir = '/tmp/guyu/'

watched_file = 'index-d-'
watched_files = {}

for file in os.listdir(watched_path):
if file.startswith(watched_file):
watched_files[file] = None

for k in watched_files.keys():
watched_files[k] = os.path.getmtime(''.join([watched_path, k]))

while True:

time.sleep(60)
print('check files')

saved_files = set(watched_files.keys())
current_files = []
for file in os.listdir(watched_path):
if file.startswith(watched_file):
current_files.append(file)

erase = list(saved_files - set(current_files))
for file in erase:
if file in watched_files:
print('delete',file)
del watched_files[file]

diff = list(set(current_files) - saved_files)
if diff:
print('diff =',diff)
for file in diff:
watched_files[file] = 0

try:
for file in watched_files.keys():
current_modified_time = os.path.getmtime(''.join([watched_path, file]))

#print('modifytime',current_modified_time, watched_files[file])
test_time = current_modified_time - watched_files[file]

if current_modified_time - watched_files[file] > 0.1:
target_file = os.path.join(target_dir, '{}_{}'.format(file, time.strftime('%Y%m%d%H%M%S')))
shutil.copy2(''.join([watched_path, file]), target_file)
watched_files[file] = current_modified_time
print('copy', target_file)

except Exception as e:
print(e)

标签:files,tool,time,watch,current,file,path,watched
From: https://www.cnblogs.com/xiaoconghua/p/17443457.html

相关文章

  • .net压缩文件(System.IO.Compression.ZipFile)
    NuGet安装System.IO.Compression.ZipFile,注意不是System.IO.Compression优点:不同于ICSharpCode.SharpZipLib.dll的地方是,这个插件可以直接压缩文件夹,文件夹内的文件自动压缩进去了,ICSharpCode.SharpZipLib.dll需要一个一个将文件添加进压缩包,不能直接压缩文件夹1ZipFile.Creat......
  • 【Oracle】Resize your Oracle datafiles down to the minimum without ORA-03297
      --Innon-multitenantDBsetlinesize1000pagesize0feedbackofftrimspoolonwithhwmas(--gethighestblockidfromeachdatafiles(fromx$ktfbueaswedon'tneedalljoinsfromdba_extents)select/*+materialize*/ktfbuesegtsnts......
  • Java-Day-25( 字节输入流 + FileInputStream 和 FileOutputStream + FileReader 和 Fi
    Java-Day-25InputStream(字节输入流)InputStream抽象类是所有类字节输入流的超类InputStream常用的子类FileInputStream:文件输入流BufferedInputStream:缓冲字节输入流ObjectInputStream:对象字节输入流FileInputStream和FileOutputStreamFileInputStream(文......
  • el-tooltip 弹出层,太宽,字压边
    业务代码如下<divv-else><el-tooltipv-if="value&&value.length>10"popper-class="popperOptions"effect="dark"v-bind:content="value.toString()"placement="top"><divclass="over......
  • RollingFileAppender[FILE] - openFile(null,true) call failed. java.io.FileNotFoun
          2023-05-2916:25:31[main]ERRORo.s.boot.SpringApplication-Applicationrunfailedjava.lang.IllegalStateException:Logbackconfigurationerrordetected:ERRORinch.qos.logback.core.rolling.RollingFileAppender[FILE]-openFile(null,true)......
  • 线上环境如何开启vue devtool
    varVue,walker,node;walker=document.createTreeWalker(document.body,1);while((node=walker.nextNode())){if(node.__vue__){Vue=node.__vue__.$options._base;if(!Vue.config.devtools){Vue.config.devtools=true;if(windo......
  • react native 使用 redux、react-redux、redux-thunk、@reduxjs/toolkit 无脑版
    导入依赖yarnaddreduxreact-reduxredux-thunk@reduxjs/toolkit 这是目录,为以下创建作为参考新建reducer文件counterReducer.jsimport{createSlice}from'@reduxjs/toolkit';constcounterSlice=createSlice({name:'counter',//名字,用途如:state.count......
  • AWS Toolkit初体验
      当今互联网时代,各种语言、技术也经常推陈出新,对于码农来说就需要及时更新自己的技能来满足自己项目的开发,最近人工智能的火爆,想找找有没有对应的开发工具,偶然的机会看到的Info的一篇亚马逊的插件,说试就试。第一步搭建环境:主要是idea和CodeWhisperer的下载和关联,关联启动好......
  • git 报错;bad config in file .gitconfig
    报错如下解决办法删除.gitconfig文件,然后重启gitbash&vscode即可正常显示分支了。记得重新设置git的账号邮箱。......
  • 关于动态渲染的组件watch监听不到传入的props的问题
    watch:{propsTime:{handler(newValue,oldValue){console.log('props',newValue)this.getOverviewData()},//这里增加了一个immediate属性,说明监听到props传参后立即先去执行handler方法immediate:true,}......