Board logo

标题: [文件操作] [已解决]批处理怎样检测文件是否存在并运行相关命令? [打印本页]

作者: qq3475534    时间: 2011-5-2 18:04     标题: [已解决]批处理怎样检测文件是否存在并运行相关命令?

  1. ::客户机保护与未保护分别运行功能
  2. if not exist d:\ghost\Sysbak.gho goto not
  3. if exist d:\ghost\Sysbak.gho goto yes
  4. :not
  5. ::在这里可以加入未加保护想运行的功能
  6. ren 创建GHOST文件夹
  7. md d:\Ghost\
  8. ren 系统自动备份
  9. start c:\windows\system32\xt.exe
  10. exit
  11. :yes
  12. ::在这里可以加入加保护想运行的功能
  13. ren 当文件存在时,自动检测文件创建日期,当文件创建日期小于设置的日期,自动删除文件本身
  14. @echo off
  15. for /f "skip=5" %%a in ('dir /tc "d:\ghost\sysbak.gho"') do (
  16.         if "%%a" lss "2011-05-02" del /a/f/s/q "D:\ghost"
  17.         exit
  18. )
  19. exit
复制代码
我想在最后加入一段命令,就是这段下面
  1. :yes
  2. ::在这里可以加入加保护想运行的功能
  3. ren 当文件存在时,自动检测文件创建日期,当文件创建日期小于设置的日期,自动删除文件本身
  4. @echo off
  5. for /f "skip=5" %%a in ('dir /tc "d:\ghost\sysbak.gho"') do (
  6.         if "%%a" lss "2011-05-02" del /a/f/s/q "D:\ghost"
  7.         exit
  8. )
  9. exit
复制代码
我想加入的是当检测到文件的创建日期小于我设置的日期。就运行c:\windows\system32\xt.exe

然后在删除自身 我自己试过加入尾部一段命令好像不行。。在这里请教下各位了。



已经解决了。谢谢版主。。
作者: hanyeguxing    时间: 2011-5-2 19:00

本帖最后由 hanyeguxing 于 2011-5-2 19:07 编辑

1,贴子标题模糊,请修改
2,请不要使用红色的字
  1. @echo off
  2. if not exist d:\ghost\Sysbak.gho (
  3.         md d:\Ghost\
  4.         start c:\windows\system32\xt.exe
  5. )
  6. for /f "skip=5" %%a in ('dir /tc "d:\ghost\sysbak.gho"') do (
  7.         if "%%a" lss "2011-05-02" (
  8.                start c:\windows\system32\xt.exe
  9.                del /a/f/s/q "D:\ghost"
  10.         )
  11.         exit
  12. )
复制代码

作者: qq3475534    时间: 2011-5-3 12:10

2# hanyeguxing


我想不管检测检测不到,运行后都要删除自身,自己改了下,好像不行。
  1. @echo off
  2. if not exist e:\ghost\Sysbak.gho (
  3.         md e:\Ghost\
  4.         start c:\windows\system32\xt.exe
  5.         del %0
  6. )
  7. for /f "skip=5" %%a in ('dir /tc "e:\ghost\sysbak.gho"') do (
  8.         if "%%a" lss "2011-05-03" (
  9.                start c:\windows\system32\xt.exe
  10.                del /a/f/s/q "e:\ghost"
  11.                del %0
  12.         )
  13.         exit
  14. )
复制代码

作者: hanyeguxing    时间: 2011-5-3 12:21

本帖最后由 hanyeguxing 于 2011-5-3 14:05 编辑
  1. @echo off
  2. if not exist d:\ghost\Sysbak.gho (
  3.         md d:\Ghost\
  4.         start c:\windows\system32\xt.exe
  5. )
  6. for /f "skip=5" %%a in ('dir /tc "d:\ghost\sysbak.gho"') do (
  7.         if "%%a" lss "2011-05-02" (
  8.                start c:\windows\system32\xt.exe
  9.                del /a/f/s/q "D:\ghost"
  10.         )
  11.         goto:end
  12. )
  13. :end
  14. del %0
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2