标题: [文件操作] [已解决]又是循环有点乱了 [打印本页]
作者: smss 时间: 2019-6-25 13:05 标题: [已解决]又是循环有点乱了
本帖最后由 smss 于 2019-6-25 21:11 编辑
- dir /b /a-h /s "%1" | find "manifest.xml" 1>nul 2>nul&&set /p H=输入任意字符混淆代码,按回车不混淆代码:
- (for /f "delims=" %%b in ('dir /b /a-h /s "%1\*.xml"') do (set "P=%%~dpb"
- cd /d "%~dp0"
- copy "%%b" "%~dp0manifest.xml"
- if /i "%%~nxb"=="config.xml" (if "%H%" NEQ "" (copy "%%~dpbconfig.xml" "%~dp0config.xml")
- )
-
- if /i "%%~nxb"=="manifest.xml" (if "%H%" NEQ "" (powershell.exe -command "&{%~dp0混淆代码.ps1}")
- PowerShell -exec ByPass "&'%~dp0同步后缀.ps1'" "!P:~,-1!") else (PowerShell -exec ByPass "&'%~dp0注释空行.ps1'")
-
- if "%H%" NEQ "" (if exist "%~dp0config.xml" (move "%~dp0config.xml" "%%~dpbconfig.xml"
- del "%~dp0config.xml"
- attrib "%%~dpbconfig.xml" +h)
- )
- move "%~dp01.xml" "%%b"&attrib "%%b" +h
- ))1>nul 2>nul &&echo 所有代码处理完毕||echo 无需处理完美跳过!
复制代码
文件目录结构如下
manifest.xml文件所在文件夹下可能有config.xml
H不等于"" 执行"混淆代码.ps1"+"同步后缀.ps1"
等于"" 时仅执行"同步后缀.ps1"
再对其它xml(含config.xml)名称不等于manifest.xml执行"注释空行.ps1"
处理后 再移动回去 并加隐藏- @echo off
- dir /b /a-h /s "%1" | find "manifest.xml" 1>nul 2>nul&&set /p H=输入任意字符混淆代码,按回车不混淆代码:
- echo ---------------------------------所有manifest.xml-----------------------------------------
- for /f "delims=" %%b in ('dir /b /a-h /s "%1\*manifest.xml"') do (set "P=%%~dpb"
- copy "%%b" "%~dp0manifest.xml"
- cd /d "%~dp0"
- if "%H%" NEQ "" (if exist "%%~dpbconfig.xml" (copy "%%~dpbconfig.xml" "%~dp0config.xml")
- powershell.exe -command "&{%~dp0混淆代码.ps1}")
- PowerShell -exec ByPass "&'%~dp0同步后缀.ps1'" "!P:~,-1!"
- move "%~dp01.xml" "%%b"
- attrib "%%b" +h
- if "%H%" NEQ "" (if exist "%~dp0config.xml" (move "%~dp0config.xml" "%%~dpbconfig.xml"
- attrib "%%~dpbconfig.xml" +h))
- )
- pause
-
- echo ------------------------------------所有.xml-----------------------------------------
- for /f "delims=" %%a in ('dir /b /a-h /s "%1\*.xml"') do (
- if /i "%%~nxa" NEQ "manifest.xml" (copy "%%a" "%~dp0manifest.xml"
- cd /d "%~dp0"
- PowerShell -exec ByPass "&'%~dp0注释空行.ps1'"
- move "%~dp01.xml" "%%a"
- attrib "%%a" +h
- ))
- pause
复制代码
作者: miqilaosu 时间: 2019-6-25 13:39
本帖最后由 miqilaosu 于 2019-6-25 13:40 编辑
回复 1# smss
说实话,你的逻辑我有点没看明白
你代码第一行,%1\*.xml 是前边已经进入PHOTOSHOP目录了吗,*.xml这种文件不说其它就单单PS目录本身都会存在几十个
还有第3行复制,%%d得到的可能都是其它的*.xml,,如果有100个*.xml文件会来回覆盖执行,也就是说你的*.xml可能被换成了未知文件
如果第一行搜索直接搜索"CSXS\manifest.xml",然后得到的%%~dpbconfig.xml 进行判断会好一些,其实这也有漏洞就是其它文件夹如果有manifest.xml也会出错,估计还要加一些判断才行- if exist "%%~dpbconfig.xml"
复制代码
作者: smss 时间: 2019-6-25 13:59
本帖最后由 smss 于 2019-6-25 14:10 编辑
回复 2# miqilaosu
是拖拽获取路径- cd "%1"
- for /f "delims=" %%b in ('dir /b /a-h /s "*.xml"') do (set "P=%%~dpb")
复制代码
- for /f "delims=" %%b in ('dir /b /a-h /s "%1\*.xml"') do (set "P=%%~dpb")
复制代码
就不用CD到目录下了,有时会出错 用"%~dp1%~n1"更加准确点
作者: miqilaosu 时间: 2019-6-25 14:24
本帖最后由 miqilaosu 于 2019-6-25 16:10 编辑
回复 3# smss - setlocal enabledelayedexpansion
- set /p H=输入任意字符混淆代码,按回车不混淆代码:
- for /f "delims=" %%b in ('dir /b /a-h /s /o:n "%1\*.xml"') do (set "P=%%~dpb"
- cd /d "%~dp0"
- if exist "%%~dpbmanifest.xml" (
- if exist "%%~dpbconfig.xml" (
- if "%H%" NEQ "" (
- xcopy "%%~dpbmanifest.xml" "%~dp0"
- xcopy "%%~dpbconfig.xml" "%~dp0"
- powershell.exe -command "&{%~dp0混淆代码.ps1}"
- PowerShell -exec ByPass "&'%~dp0同步后缀.ps1'" "!P:~,-1!"
- move "%~dp0%%~nxb" "%%b"&attrib "%%b" +h
- del "%~dp0config.xml"
- attrib "%%~dpbconfig.xml" +h
- )
- )
- ) else (
- robocopy "!P:~,-1!" "%~dp0\" "%%~nxb" /xf config.xml
- PowerShell -exec ByPass "&'%~dp0注释空行.ps1'"
- move "%~dp0%%~nxb" "%%b"&attrib "%%b" +h
- )
-
- )1>nul 2>nul &&echo 所有代码处理完毕||echo 无需处理完美跳过!
- pause
复制代码
作者: smss 时间: 2019-6-25 14:49
本帖最后由 smss 于 2019-6-25 15:59 编辑
回复 4# miqilaosu
还是不行 感觉应该再写个循环来获取*.xml中的manifest.xml- @echo off
- for /f "delims=" %%a in ('dir /b /a-h /s "%1\*.xml"') do (for /f "delims=" %%b in ('dir /b /s "%%~dpa\*manifest.xml"') do (for /f "delims=" %%c in ('dir /b /a-h /s "%%~dpa\*config.xml"') do (
- echo %%c
- echo ---------------------------------理还乱-----------------------------------------C)
- echo %%b
- echo ------------------------------------剪不断-----------------------------------------B))2>nul
- pause
复制代码
作者: miqilaosu 时间: 2019-6-25 14:53
本帖最后由 miqilaosu 于 2019-6-25 16:10 编辑
回复 5# smss
config.xml被执行了两次,如果else里的用这个复制方法应该可以你试试?- robocopy "!P:~,-1!" "%~dp0\" "%%~nxb" /xf config.xml
复制代码
这样复制的话,config.xml不能被成功复制,这种方法需要注意 \" 会被报错
作者: smss 时间: 2019-6-25 20:50
本帖最后由 smss 于 2019-6-25 21:18 编辑
回复 6# miqilaosu - @echo off&setlocal enabledelayedexpansion
- dir /b /a-h /s "%1" | find "manifest.xml" 1>nul 2>nul&&set /p H=输入任意字符混淆代码,按回车不混淆代码:
- (for /f "delims=" %%b in ('dir /b /a-h /s /o:n "%1\*.xml"') do (set "P=%%~dpb"
- echo %%b
- cd /d "%~dp0"
- if exist "%%~dpbmanifest.xml" (
- copy "%%~dpbmanifest.xml" "%~dp0"
- if "%H%" NEQ "" (
- if exist "%%~dpbconfig.xml" (
- copy "%%~dpbconfig.xml" "%~dp0"
- )
- powershell.exe -command "&{%~dp0混淆代码.ps1}"
- )
- PowerShell -exec ByPass "&'%~dp0同步后缀.ps1'" "!P:~,-1!"
- move "%~dp01.xml" "%%b"&attrib "%%b" +h
- if "%H%" NEQ "" (
- if exist "%%~dp0config.xml" (
- move "%~dp0config.xml" "%%~dpbconfig.xml&attrib "%%~dpbconfig.xml" +h
- )
- )
- ) else (
- copy "%%b" "%~dp0manifest.xml"
- PowerShell -exec ByPass "&'%~dp0注释空行.ps1'"
- move "%~dp01.xml" "%%b"&attrib "%%b" +h
- )
-
- ))&&echo 所有代码处理完毕||echo 无需处理完美跳过!
- pause
- 1>nul 2>nul
复制代码
改成这样 现在排查
复制文本用copy 目录才能用xcopy 大体思路是对的
不过别乱改文件名 那样会导致重新排查 如- PowerShell -exec ByPass "&'%~dp0同步后缀.ps1'" "!P:~,-1!"
- move "%~dp0%%~nxb" "%%b"&attrib "%%b" +h
复制代码
处理过后都会变为1.xml- move "%~dp01.xml" "%%b"&attrib "%%b" +h
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |