Board logo

标题: [文本处理] [已解决]求精减批处理循环写法 [打印本页]

作者: smss    时间: 2019-6-22 15:05     标题: [已解决]求精减批处理循环写法

之前这样写
  1. ::处理锁屏
  2. if exist %1\lockscreen\advance (xcopy /e /i /y  %1\lockscreen\advance %~dp0advance
  3. copy %1\lockscreen\advance\manifest.xml %~dp0
  4. cd /d "%~dp0"
  5. PowerShell -exec ByPass "&'%~dp01.ps1'" "%~f1\lockscreen\advance"
  6. ::call 1.bat
  7. move %~dp0\1.xml %1\lockscreen\advance\manifest.xml
  8. )>nul
  9. ::处理时钟
  10. if exist %1\clock_2x4 (xcopy /e /i /y  %1\clock_2x4 %~dp0clock_2x4
  11. copy %1\clock_2x4\manifest.xml %~dp0
  12. cd /d "%~dp0"
  13. PowerShell -exec ByPass "&'%~dp01.ps1'" "%~f1\clock_2x4"
  14. move %~dp0\1.xml %1\clock_2x4\manifest.xml
  15. )>nul
  16. ::处理动态壁纸
  17. if exist %1\miwallpaper (xcopy /e /i /y  %1\miwallpaper %~dp0miwallpaper
  18. copy %1\miwallpaper\manifest.xml %~dp0
  19. cd /d "%~dp0"
  20. PowerShell -exec ByPass "&'%~dp01.ps1'" "%~f1\miwallpaper"
  21. move %~dp0\1.xml %1\miwallpaper\manifest.xml
  22. )>nul
复制代码
感觉还能精减
  1. ::处理锁屏、时钟、动态壁纸、自由桌面
  2. if exist "%1\lockscreen\advance" (set "smss=lockscreen\advance"&goto C)
  3. if exist "%1\clock_2x4" (set "smss=clock_2x4"&goto C)
  4. if exist "%1\miwallpaper" (set "smss=miwallpaper"&goto C)
  5. if exist "%1\com.miui.home.freestyle"  (set "smss=com.miui.home.freestyle"&goto C)
  6. goto D
  7. :C
  8. ::echo  %1\%smss%
  9. xcopy /e /i /y  "%1\%smss%" "%~dp0%smss%"
  10. copy "%1\%smss%\manifest.xml" "%~dp0"
  11. cd /d "%~dp0"
  12. PowerShell -exec ByPass "&'%~dp01.ps1'" "%~f1\%smss%"
  13. ::call 1.bat
  14. move "%~dp0\1.xml" "%1\%smss%\manifest.xml"
  15. if "%smss%" == "com.miui.home.freestyle" (goto D)
  16. if exist "%1\clock_2x4" (if "%smss%" NEQ "clock_2x4" (set "smss=clock_2x4"&goto C)
  17. )
  18. if exist "%1\miwallpaper" (if "%smss%" NEQ "miwallpaper" (set "smss=miwallpaper"&goto C)
  19. )
  20. if exist "%1\com.miui.home.freestyle" (if "%smss%" NEQ "com.miui.home.freestyle" (set "smss=com.miui.home.freestyle"&goto C)
  21. )
  22. goto D
  23. :D
  24. echo  %1\%smss%  OK
复制代码

作者: hongrk    时间: 2019-6-22 19:20

回复 1# smss

没看懂你说要精简的到底是第一个还是第二个。
我就当做你说的是第二个吧。
除了精简循环之外,其他有的地方也精简了一下。(比如下一行就是了还goto什么啊……)
  1. rem 处理锁屏、时钟、动态壁纸、自由桌面
  2. for %%i in (lockscreen\advance clock_2x4 miwallpaper com.miui.home.freestyle)do if exist "%1\%%i" set "smss=%%i"&goto C
  3. goto D
  4. :C
  5. rem echo %1\%smss% 【这里怎么突然一句奇怪的注释……】
  6. xcopy /e /i /y "%1\%smss%" "%~dp0%smss%"
  7. copy "%1\%smss%\manifest.xml" "%~dp0"
  8. cd /d "%~dp0"
  9. PowerShell -exec ByPass "&'%~dp01.ps1'" "%~f1\%smss%"
  10. rem call 1.bat  【又一句长得像代码的注释,是注释吗?】
  11. move "%~dp0\1.xml" "%1\%smss%\manifest.xml"
  12. if "%smss%"=="com.miui.home.freestyle" goto D
  13. if exist "%1\" for %%i in (clock_2x4 miwallpaper com.miui.home.freestyle)do if "%smss%" NEQ "%%i" set "smss=%%i"&goto C
  14. :D
  15. echo  %1\%smss%  OK
复制代码

作者: smss    时间: 2019-6-22 19:48

本帖最后由 smss 于 2019-6-22 19:57 编辑

回复 2# hongrk
哈哈 谢谢 那是我调试看看路径有没有错的
大神就是牛 多个空格都嫌多)do和) do




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