批处理监视一个文件夹并解压缩每个文件



我们的ERP程序生成包含.xml文档的.zip文件。我需要确保每个.zip文件都被提取到目标文件夹中。我发现了一个比较两个日志文件的批处理脚本,但我不知道如何处理新的(尚未解压缩的)文件

@echo off
if not exist c:OldDir.txt echo. > c:OldDir.txt
dir /b "C:SpektraGelen" > c:NewDir.txt
set equal=no
fc c:OldDir.txt c:NewDir.txt | find /i "no differences" > nul && set   equal=yes
copy /y c:Newdir.txt c:OldDir.txt > nul
if %equal%==yes goto :eof
rem Your batch file lines go here
**********
c:unzip.exe (the_new_files) -d (destination)
*******************

这是的脚本

我需要处理旧日志文件上不存在的新文件

感谢

要了解相对于旧日志文件OldDir.txt,哪些行已添加到新日志文件C:NewDir.txt中,可以使用findstr命令,该命令具有选项/G,用于指定包含搜索字符串的文件。与/X(精确匹配)和/V(返回不匹配行)一起,只返回NewDir.txt中已添加的行,假设每一行都是唯一的:

findstr /V /X /I /G:"C:OldDir.txt" "C:NewDir.txt"

要处理返回的项目,请使用for /F循环捕获它们:

for /F "eol=| delims=" %%F in ('
findstr /V /X /I /G:"C:OldDir.txt" "C:NewDir.txt"
') do (
rem // Do whatever you want with each file in `%%F`...
)

所以你的脚本可能是这样的:

@echo off
rem // Change to the working directory `C:` once:
pushd "C:" || exit /B 1 & rem/ ("C:" is the root directory of drive "C:")
rem // Ensure `OldDir.txt` exists by appending nothing:
>> "OldDir.txt" rem/
rem // Create new log file `NewDir.txt`:
> "NewDir.txt" dir /B "C:SpektraGelen"
rem // Process all newly added items in `NewDir`:
for /F "eol=| delims=" %%F in ('
findstr /V /X /I /G:"OldDir.txt" "NewDir.txt"
') do (
rem // Do whatever you want with each file in `%%F`:
unzip "%%F" -d "C:somedestinationfolder"
)
rem // Move new log file onto old one, suppress report message:
> nul move /Y "NewDir.txt" "OldDir.txt"
rem // Restore previous working directory:
popd

相关内容

  • 没有找到相关文章

最新更新