标题: [文本处理] [已解决]求精减批处理循环写法 [打印本页]
作者: smss 时间: 2019-6-22 15:05 标题: [已解决]求精减批处理循环写法
之前这样写- ::处理锁屏
- if exist %1\lockscreen\advance (xcopy /e /i /y %1\lockscreen\advance %~dp0advance
- copy %1\lockscreen\advance\manifest.xml %~dp0
- cd /d "%~dp0"
- PowerShell -exec ByPass "&'%~dp01.ps1'" "%~f1\lockscreen\advance"
- ::call 1.bat
- move %~dp0\1.xml %1\lockscreen\advance\manifest.xml
- )>nul
- ::处理时钟
- if exist %1\clock_2x4 (xcopy /e /i /y %1\clock_2x4 %~dp0clock_2x4
- copy %1\clock_2x4\manifest.xml %~dp0
- cd /d "%~dp0"
- PowerShell -exec ByPass "&'%~dp01.ps1'" "%~f1\clock_2x4"
- move %~dp0\1.xml %1\clock_2x4\manifest.xml
- )>nul
- ::处理动态壁纸
- if exist %1\miwallpaper (xcopy /e /i /y %1\miwallpaper %~dp0miwallpaper
- copy %1\miwallpaper\manifest.xml %~dp0
- cd /d "%~dp0"
- PowerShell -exec ByPass "&'%~dp01.ps1'" "%~f1\miwallpaper"
- move %~dp0\1.xml %1\miwallpaper\manifest.xml
- )>nul
复制代码
感觉还能精减- ::处理锁屏、时钟、动态壁纸、自由桌面
- if exist "%1\lockscreen\advance" (set "smss=lockscreen\advance"&goto C)
- if exist "%1\clock_2x4" (set "smss=clock_2x4"&goto C)
- if exist "%1\miwallpaper" (set "smss=miwallpaper"&goto C)
- if exist "%1\com.miui.home.freestyle" (set "smss=com.miui.home.freestyle"&goto C)
- goto D
- :C
- ::echo %1\%smss%
- xcopy /e /i /y "%1\%smss%" "%~dp0%smss%"
- copy "%1\%smss%\manifest.xml" "%~dp0"
- cd /d "%~dp0"
- PowerShell -exec ByPass "&'%~dp01.ps1'" "%~f1\%smss%"
- ::call 1.bat
- move "%~dp0\1.xml" "%1\%smss%\manifest.xml"
- if "%smss%" == "com.miui.home.freestyle" (goto D)
-
- if exist "%1\clock_2x4" (if "%smss%" NEQ "clock_2x4" (set "smss=clock_2x4"&goto C)
- )
- if exist "%1\miwallpaper" (if "%smss%" NEQ "miwallpaper" (set "smss=miwallpaper"&goto C)
- )
- if exist "%1\com.miui.home.freestyle" (if "%smss%" NEQ "com.miui.home.freestyle" (set "smss=com.miui.home.freestyle"&goto C)
- )
- goto D
- :D
- echo %1\%smss% OK
复制代码
作者: hongrk 时间: 2019-6-22 19:20
回复 1# smss
没看懂你说要精简的到底是第一个还是第二个。
我就当做你说的是第二个吧。
除了精简循环之外,其他有的地方也精简了一下。(比如下一行就是了还goto什么啊……)- rem 处理锁屏、时钟、动态壁纸、自由桌面
- for %%i in (lockscreen\advance clock_2x4 miwallpaper com.miui.home.freestyle)do if exist "%1\%%i" set "smss=%%i"&goto C
- goto D
- :C
- rem echo %1\%smss% 【这里怎么突然一句奇怪的注释……】
- xcopy /e /i /y "%1\%smss%" "%~dp0%smss%"
- copy "%1\%smss%\manifest.xml" "%~dp0"
- cd /d "%~dp0"
- PowerShell -exec ByPass "&'%~dp01.ps1'" "%~f1\%smss%"
- rem call 1.bat 【又一句长得像代码的注释,是注释吗?】
- move "%~dp0\1.xml" "%1\%smss%\manifest.xml"
- if "%smss%"=="com.miui.home.freestyle" goto D
-
- if exist "%1\" for %%i in (clock_2x4 miwallpaper com.miui.home.freestyle)do if "%smss%" NEQ "%%i" set "smss=%%i"&goto C
- :D
- 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 |