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

[日期时间] [已解决]批处理如何编写按时间要求执行程序的命令?

具体要求:
如果今天是星期四,则执行xcopy xxxx xxxx,接着再按顺序执行后面的命令,如果不是星期四则跳过xcopy xxxx xxxx命令,按顺序执行后面的命令。
为什么运行到空行之后就不能再运行后面的命令了,也就是运行到“start %temp%\aaa.bat”之后,后面的命令就不能被执行了,另外:在运行这个P的时候会有一个黑的P窗口出现,如何让他不出现。求大大们帮忙,谢谢
  1. ::每星期四备份一次收藏夹
  2. echo if  "%%date:~-1%%"  == "四" call:thursday>>%temp%\aaa.bat
  3. echo goto :eof>>%temp%\aaa.bat
  4. echo :thursday>>%temp%\aaa.bat
  5. echo xcopy /e /h /i /k /y D:\Favorites\* E:\Favorites>>%temp%\aaa.bat
  6. echo goto :eof>>%temp%\aaa.bat
  7. start %temp%\aaa.bat
  8. taskkill /f /im IExplore.exe
  9. del /f /s /q "%userprofile%\Local Settings\History\*"
  10. attrib -s -h "%userprofile%\Local Settings\Temporary Internet Files\Content.IE5\*">nul 2>nul
  11. del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\Content.IE5\*">nul 2>nul
  12. rd /s /q "%userprofile%\Local Settings\Temporary Internet Files\Content.IE5">nul 2>nul
复制代码
以下是我自己的解决方法(其实大同小异),留给和我一样不懂批处理的人的一个参考,高手莫笑
  1. @echo off
  2. ::每周四备份IE收藏夹到"E:\Favorites"下
  3. Setlocal enabledelayedexpansion
  4. for /f "skip=2 delims=: tokens=1,*" %%i in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Favorites') do (
  5.    set str=%%i
  6.    set var=%%j
  7.    set "var=!var:"=!"
  8.    if not "!var:~-1!"=="=" echo xcopy /e /h /i /k /y !str:~-1!:!var!\* e:\Favorites\>%temp%\aaa.bat
  9. )
  10. if  "%date:~-1%"  == "四" call %temp%\aaa.bat
  11. taskkill /f /im IExplore.exe
  12. del /f /s /q "%userprofile%\Local Settings\History\*"
  13. attrib -s -h "%userprofile%\Local Settings\Temporary Internet Files\Content.IE5\*">nul 2>nul
  14. del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\Content.IE5\*">nul 2>nul
  15. rd /s /q "%userprofile%\Local Settings\Temporary Internet Files\Content.IE5">nul 2>nul
复制代码
1

评分人数

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

这里有个函数可以判断星期几
http://www.bathome.net/thread-3056-1-1.html
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

本帖最后由 wwjpl 于 2013-3-2 00:38 编辑

回复 2# Batcher


    谢谢你的帮助,我知道用“%date%”这个命令判断今天是星期几,只是后面的连接部分不会写,也就是满足条件进行拷贝命令不会连接。
我不会解决这个问题,我就用输出的笨办法调用批处理,可问题是运行到空行之后就不能再运行后面的命令了,也就是运行到“start %temp%\aaa.bat”之后,后面的命令就不能被执行了,求大大帮忙,谢谢
  1. ::每星期四备份一次收藏夹
  2. echo if  "%%date:~-1%%"  == "四" call:thursday>>%temp%\aaa.bat
  3. echo goto :eof>>%temp%\aaa.bat
  4. echo :thursday>>%temp%\aaa.bat
  5. echo xcopy /e /h /i /k /y D:\Favorites\* E:\Favorites>>%temp%\aaa.bat
  6. echo goto :eof>>%temp%\aaa.bat
  7. start %temp%\aaa.bat
  8. taskkill /f /im IExplore.exe
  9. del /f /s /q "%userprofile%\Local Settings\History\*"
  10. attrib -s -h "%userprofile%\Local Settings\Temporary Internet Files\Content.IE5\*">nul 2>nul
  11. del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\Content.IE5\*">nul 2>nul
  12. rd /s /q "%userprofile%\Local Settings\Temporary Internet Files\Content.IE5">nul 2>nul
复制代码

TOP

回复 3# wwjpl


    你的start命令在哪里?是不是代码贴错了

TOP

本帖最后由 wwjpl 于 2013-3-2 00:47 编辑

回复 4# BAT-VBS


    帖子已经更正过了,加入了“start”之后可以运行正常了,可是会出现一个DOS窗口,我不想他出现,
我尝试在开头加入“echo if not "%%1"=="wind" mshta vbscript:createobject("wscript.shell").run("""%%~f0"" wind",vbhide)(window.close)^&^&exit>>%temp%\aaa.bat”,运行后还是会出现DOS窗口,请问如何解决?谢谢帮助。

TOP

回复 5# wwjpl
  1. ::每星期四备份一次收藏夹
  2. echo if not "%%1"=="wind" mshta vbscript:createobject("wscript.shell").run("""%%~f0"" wind",vbhide)(window.close)^&^&exit>%temp%\aaa.bat
  3. echo if  "%%date:~-1%%"  == "四" call:thursday>>%temp%\aaa.bat
  4. echo goto :eof>>%temp%\aaa.bat
  5. echo :thursday>>%temp%\aaa.bat
  6. echo xcopy /e /h /i /k /y D:\Favorites\* E:\Favorites>>%temp%\aaa.bat
  7. echo goto :eof>>%temp%\aaa.bat
  8. start %temp%\aaa.bat
  9. taskkill /f /im IExplore.exe
  10. del /f /s /q "%userprofile%\Local Settings\History\*"
  11. attrib -s -h "%userprofile%\Local Settings\Temporary Internet Files\Content.IE5\*">nul 2>nul
  12. del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\Content.IE5\*">nul 2>nul
  13. rd /s /q "%userprofile%\Local Settings\Temporary Internet Files\Content.IE5">nul 2>nul
复制代码
你的代码是这样写的吗?
start命令加个/b可以吗?
1

评分人数

    • wwjpl: 乐于助人 谢谢帮助我们这些末学后进技术 + 1

TOP

回复 6# BAT-VBS

首先 谢谢你的帮助
    “/b”这个参数我没试过,不过我把start改成call完美执行了,不过最终我是用“if  "%date:~-1%"  == "六" call %temp%\aaa.bat”这个命令解决问题的,具体见顶楼。

再次谢谢你的帮助。

TOP

返回列表