파일을 압축하거나 압축 해제하는 BAT 파일을 만들고 싶습니다. 파일 압축과 관련하여 이 질문을 찾았습니다: https://superuser.com/questions/110991/can-you-zip-a-file-from-the-command-prompt-using-only-windows-built-in-capabili/112094
거기에 제공된 답변은 훌륭하고 저에게 효과적이지만 파일 압축을 푸는 방법에 대한 정보를 찾을 수 없습니다. 링크에서와 같이 타사 도구(winRAR 제외)는 사용할 수 없습니다.
미리 감사드리며 영어 실수에 대해 죄송합니다.
이 배치 파일 코드는 파일의 압축을 푸는 데 도움이 됩니다.
@echo off
setlocal
cd /d %~dp0
Call :UnZipFile "C:\Temp\" "c:\FolderName\batch.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%
N.B. C:\Temp는 추출된 (압축 해제) 파일을 저장하는 폴더입니다.
그리고 c:\FolderName\batch.zip은 소스 경로(Zip 파일이 저장된 곳)입니다.
필요에 따라 전체 파일 경로 (드라이브, 폴더 및 Zip 파일 이름)를 변경하십시오 . .
ZipFile="C:\Users\spvaidya\Music\folder.zip"
ExtractTo="C:\Users\spvaidya\Music\"
'If the extraction location does not exist create it.
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(ExtractTo) Then
fso.CreateFolder(ExtractTo)
End If
'Extract the contants of the zip file.
set objShell = CreateObject("Shell.Application")
set FilesInZip=objShell.NameSpace(ZipFile).items
objShell.NameSpace(ExtractTo).CopyHere(FilesInZip)
Set fso = Nothing
Set objShell = Nothing
다음 vbscript를 file.vbs로 저장한 다음 다음과 같은 배치 스크립트를 사용하여 실행할 수 있습니다:
file.vbs
.bat 파일에 저장하고 실행합니다.