批处理文件解析文本文件从UNIX



我正试图写一个批处理文件,从我的安卓手机备份文件到我的电脑。这个过程的一部分是让我的手机使用android调试桥生成一个文件列表作为文本文件,然后根据包含我备份手机的7zip存档文件列表的文本文件检查这个文件。

问题是使用android调试桥生成的文件列表似乎不能正确解析。

"C:%USERPROFILE%adbadb.exe" shell ls /sdcard/TWRP/BACKUPS/0149BCAA1301701A > androidlist2.txt
"C:Program Files7-zip7z.exe" l TWRPBackups.t7z > archivelist.txt
type archivelist.txt | findstr TWRPBACKUPS149BCAA1301701A > results.txt
del archivelist.txt
setLocal EnableDelayedExpansion
FOR /F "tokens=* usebackq" %%c IN (results.txt) DO (
  SET RESULT=%%c
  SET RESULT=!RESULT:~83!
  REM Writes the trimmed line to the output file
  ECHO !RESULT!>>"archivelist2.txt"
)
findstr /V /L  archivelist2.txt >> archivelist.txt
findstr /V /L * androidlist2.txt >> androidlist.txt
del results.txt
del archivelist2.txt
findstr /vixg:"archivelist.txt" androidlist.txt > discrepancies.txt
for /f "tokens=*" %%j in (discrepancies.txt) do (
"C:%USERPROFILE%adbadb.exe" pull /sdcard/TWRP/BACKUPS/0149BCAA1301701A/%%j/ TWRP/BACKUPS/0149BCAA1301701A/%%j
)

我知道我的代码是一个可怕的拼凑;我是新手。但是我在前两行中所做的是将文件列表作为文本文件,分别从我的手机的android shell和7zip存档中提取。之后,我将这两个文件删减,只留下文件名,并比较文本文件中的差异。

问题是最后一步,读取discreances .txt并从手机中提取相关文件。我注意到,如果我手动转到discrecies .txt并替换换行符(转到每行的末尾,按delete键,按enter键),文件就会正确解析。如何避免或解决这个问题?

试试这个,它可能对有帮助:

for /f "tokens=*" %%j in (discrepancies.txt) do (
for /f "delims=" %%x in ("%%j") do (
"C:%USERPROFILE%adbadb.exe" pull /sdcard/TWRP/BACKUPS/0149BCAA1301701A/%%x/ TWRP/BACKUPS/0149BCAA1301701A/%%x
))

最新更新