[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

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

  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

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



已经解决了。谢谢版主。。
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

本帖最后由 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. )
复制代码
寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

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. )
复制代码

TOP

本帖最后由 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
复制代码
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样技术 + 1
寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

返回列表