我有一个拼凑在一起的批处理脚本,可以使用内置的VBS提取单个zip文件。我现在正试图使其读取文件夹中的多个文件,并在保存之前将datetime戳附加到文件名中。
处理一个文件是这样的:
cd /d %~dp0
Call :UnZipFile "%~dp0UNZIPPED\" "%~dp0dvt_trans_C_20190517123318.dat.zip"
exit /b
:UnZipFile <ExtractTo> <newzipfile>
set vbs="%temp%\_.vbs"
if exist %vbs% del /f /q %vbs%
>%vbs% echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%vbs% echo If NOT fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Application")
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%
尝试与/ r循环:
setlocal
cd /d %~dp0
for /r %%v in (*.zip) do
Call :UnZipFile "%~dp0UNZIPPED\" "%%v"
exit /b
似乎没有将文件名传递给vbs
然后,我尝试将datetime追加到文件名的末尾,这里:
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
但是我什至不知道从哪里开始。
想法?
答案 0 :(得分:0)
所有与
一起使用setlocal
cd /d %~dp0
for /r %%G in (*.zip) do Call :UnZipFile "%~dp0UNZIPPED\" "%%G"
exit /b
:UnZipFile <ExtractTo> <newzipfile>
set vbs="%temp%\_.vbs"
if exist %vbs% del /f /q %vbs%
>%vbs% echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%vbs% echo If NOT fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Application")
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%
cd /d %~dp0UNZIPPED
ren *.dat "* %Date:/= % %Time::=.%.*"