这是我到目前为止(它应该将zip %1
解压缩到桌面%2
上的文件夹):
@echo off
set from=%1
set to=%2
set tem=C:\Users\%username%\temp_tempExtract
rd /s /q %tem%
mkdir %tem%
xcopy %from% %tem%
rd /s /q %from%
FOR %%F IN (%test_firmware_dir%\*.zip) DO (
set zip=%%F
goto cont
)
:cont
jar xf %zip%
del /q %zip%
mkdir C:\Users\%username%\Desktop\%to%
xcopy %temp% C:\Users\%username%\Desktop\%to%
rd /s /q %tem%
cls
cd C:\Users\%username%\Desktop\%to%
dir
@echo on
关于如何让它做我想要的任何想法?为此,我想我可以将.zip移动到临时文件夹(即在那里创建另一个),删除old.zip,在temp文件夹中解压缩new.zip,删除new.zip,移动所有内容temp文件夹到用户指定的文件夹(在桌面上),最后删除临时文件夹和cls / cd到桌面文件夹/显示内容。
它将创建临时文件,删除old.zip和推测移动并删除new.zip,但它永远不会将文件复制到桌面上的文件夹,也不会清除屏幕(cls
)。虽然我相信它会显示内容(dir
)。它也不会删除临时文件夹。
答案 0 :(得分:1)
以下是我认为您要执行的注释批处理代码:
将批处理文件启动时指定为第一个参数的ZIP文件解压缩到用户桌面上指定为第二个参数的文件夹中,使用jar
进行提取。
@echo off
rem Get first parameter - name of ZIP file - without double quotes.
set ZipFileFull=%~1
rem Exit batch file if no parameter was specified at all on running batch file.
if "%ZipFileFull%"=="" goto :EOF
rem Exit batch file if ZIP file does not exist.
if not exist "%ZipFileFull%" goto :EOF
set ZipFileName=%~nx1
rem Get second parameter - name of target folder on desktop - without double quotes.
set TargetFolder=%~2
if "%TargetFolder%"=="" goto :EOF
rem Test if target folder on user's desktop already exists.
if exist "%USERPROFILE%\Desktop\%TargetFolder%" (
rem Yes, it exists. Delete it with all subfolders.
rd /s /q "%USERPROFILE%\Desktop\%TargetFolder%"
if errorlevel 1 goto :EOF
)
rem Create the target folder on user's desktop.
mkdir "%USERPROFILE%\Desktop\%TargetFolder%"
rem Move the ZIP file to the target folder.
move "%ZipFileFull%" "%USERPROFILE%\Desktop\%TargetFolder%"
if errorlevel 1 goto :EOF
rem Set target folder as working directory.
cd /D "%USERPROFILE%\Desktop\%TargetFolder%"
rem Extract the files and folders in the ZIP file to target folder.
rem It would be better to specify jar.exe with full path in double quotes.
jar.exe xf "%ZipFileName%"
rem Delete the ZIP file.
del "%ZipFileName%"