Board logo

标题: [文本处理] [已解决]根据星期生成文件内容的批处理怎样优化? [打印本页]

作者: bigfoot_fv    时间: 2013-3-14 10:44     标题: [已解决]根据星期生成文件内容的批处理怎样优化?

本帖最后由 bigfoot_fv 于 2013-3-24 20:35 编辑

目录下已存在 周一~周日.txt 文件

双击后的情况:一闪,优雅地消失。。。。吴雨

           请教:
                请教:


1.可以不用临时文件实现?怎么实现呢?

2.代码可以再简化一点吗?

3.谢谢
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. echo %date%>tmp1.txt
  4. for /f "tokens=2 delims= " %%i in (tmp1.txt) do (
  5.   if "%%i"=="周一" echo 周二>tmp2.txt
  6.   if "%%i"=="周二" echo 周三>tmp2.txt
  7.   if "%%i"=="周三" echo 周四>tmp2.txt
  8.   if "%%i"=="周四" echo 周五>tmp2.txt
  9.   if "%%i"=="周五" echo 周六>tmp2.txt
  10.   if "%%i"=="周六" echo 周日>tmp2.txt
  11.   if "%%i"=="周日" echo 周一>tmp2.txt  
  12.   )
  13. for %%j in (tmp2.txt) do (type %%j.txt)
  14. del /f /q tmp1.txt
  15. del /f /q tmp2.txt
  16. pause>nul&&exit
复制代码

作者: BAT-VBS    时间: 2013-3-14 11:49

  1. @echo off
  2. for /f "tokens=2 delims= " %%i in ('%date%') do (
  3.     if "%%i"=="周一" (
  4.         echo 周二>tmp2.txt
  5.     ) else if "%%i"=="周二" (
  6.         echo 周三>tmp2.txt
  7.     ) else if "%%i"=="周三" (
  8.         echo 周四>tmp2.txt
  9.     ) else if "%%i"=="周四" (
  10.         echo 周五>tmp2.txt
  11.     ) else if "%%i"=="周五" (
  12.         echo 周六>tmp2.txt
  13.     ) else if "%%i"=="周六" (
  14.         echo 周日>tmp2.txt
  15.     ) else if "%%i"=="周日" (
  16.         echo 周一>tmp2.txt
  17.     )
  18. )
  19. for %%j in (tmp2.txt) do (
  20.     type %%j.txt
  21. )
  22. del /f /q tmp2.txt
  23. pause
复制代码

作者: BAT-VBS    时间: 2013-3-14 11:50

  1. @echo off
  2. for /f "tokens=2 delims= " %%i in ('%date%') do (
  3.     if "%%i"=="周一" (
  4.         type 周二.txt
  5.     ) else if "%%i"=="周二" (
  6.         type 周三.txt
  7.     ) else if "%%i"=="周三" (
  8.         type 周四.txt
  9.     ) else if "%%i"=="周四" (
  10.         type 周五.txt
  11.     ) else if "%%i"=="周五" (
  12.         type 周六.txt
  13.     ) else if "%%i"=="周六" (
  14.         type 周日.txt
  15.     ) else if "%%i"=="周日" (
  16.         type 周一.txt
  17.     )
  18. )
  19. pause
复制代码

作者: Marks    时间: 2013-3-14 20:39

本帖最后由 Marks 于 2013-3-14 20:54 编辑

顶楼12行的括弧是什么呀?
  1. @echo off&setlocal enabledelayedexpansion
  2. for %%i in (一二 二三 三四 四五 五六 六日 日一) do (
  3.    set a=%%i&set "周!a:~,1!=周!a:~1!"
  4. )
  5. for /f "tokens=2" %%i in ("%date%") do type !%%i!.txt
  6. pause
复制代码

作者: bigfoot_fv    时间: 2013-3-24 20:32

回复 4# Marks


    谢谢指导
作者: bigfoot_fv    时间: 2013-3-24 20:33

回复 3# BAT-VBS


    感谢多种方法指导。
作者: bigfoot_fv    时间: 2013-3-26 22:44

回复 3# BAT-VBS


忘了提醒,也许是WIN7 。兄台的第二行
  1. ('%date%')
复制代码
单引号改为双引号才可以,不然会提醒找不到文件。




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