Advertisement
aveyo

CAB

Sep 17th, 2017
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.23 KB | None | 0 0
  1. @echo off &echo. &set "ext=%~x1" &title CAB [%1] &rem input file or folder / 'files' folder / unpacks .cab .??_
  2. if "_%1"=="_" if not exist "%~dp0files" echo CAB: No input and no 'files' directory to pack &goto :Exit "do nothing"
  3. if "_%1"=="_" if exist "%~dp0files" call :CabDir "%~dp0files" &goto :Exit "input = none, use 'files' directory -pack"
  4. for /f "tokens=1 delims=r-" %%I in ("%~a1") do if "_%%I"=="_d" call :CabDir "%~f1" &goto :Exit "input = dir -pack"
  5. if not "_%~x1"=="_.cab" if not "_%ext:~-1%"=="__" call :CabFile "%~f1" &goto :Exit "input = file -pack"
  6. call :CabExtract "%~f1" &goto :Exit "input = .cab or .??_ -unpack"
  7. :Exit AveYo: script will add a CAB entry to right-click -- SendTo menu
  8. if not exist "%APPDATA%\Microsoft\Windows\SendTo\CAB.bat" copy /y "%~f0" "%APPDATA%\Microsoft\Windows\SendTo\CAB.bat" >nul 2>nul
  9. ping -n 6 localhost >nul &title cmd.exe &exit /b
  10. :CabExtract %1:[.cab or .xx_]
  11. echo %1 &pushd "%~dp1" &mkdir "%~n1" >nul 2>nul &expand -R "%~1" -F:* "%~n1" &popd &goto :eof
  12. :CabFile %1:[filename]
  13. echo %1 &pushd "%~dp1" &makecab /D CompressionType=LZX /D CompressionLevel=7 /D CompressionMemory=21 "%~nx1" "%~n1.cab" &goto :eof  
  14. :CabDir %1:[directory]
  15. dir /a:-D/b/s "%~1"
  16. set "ddf="%temp%\ddf""
  17. echo/.New Cabinet>%ddf%
  18. echo/.set Cabinet=ON>>%ddf%
  19. echo/.set CabinetFileCountThreshold=0;>>%ddf%
  20. echo/.set Compress=ON>>%ddf%
  21. echo/.set CompressionType=LZX>>%ddf%
  22. echo/.set CompressionLevel=7;>>%ddf%
  23. echo/.set CompressionMemory=21;>>%ddf%
  24. echo/.set FolderFileCountThreshold=0;>>%ddf%
  25. echo/.set FolderSizeThreshold=0;>>%ddf%
  26. echo/.set GenerateInf=OFF>>%ddf%
  27. echo/.set InfFileName=nul>>%ddf%
  28. echo/.set MaxCabinetSize=0;>>%ddf%
  29. echo/.set MaxDiskFileCount=0;>>%ddf%
  30. echo/.set MaxDiskSize=0;>>%ddf%
  31. echo/.set MaxErrors=1;>>%ddf%
  32. echo/.set RptFileName=nul>>%ddf%
  33. echo/.set UniqueFiles=ON>>%ddf%
  34. setlocal enabledelayedexpansion
  35. pushd "%~dp1"
  36. for /f "tokens=* delims=" %%D in ('dir /a:-D/b/s "%~1"') do (
  37.  set "DestinationDir=%%~dpD" &set "DestinationDir=!DestinationDir:%~1=!" &set "DestinationDir=!DestinationDir:~0,-1!"
  38.  echo/.Set DestinationDir=!DestinationDir!;>>%ddf%
  39.  echo/"%%~fD"  /inf=no;>>%ddf%
  40. )
  41. makecab /F %ddf% /D DiskDirectory1="" /D CabinetNameTemplate=%~nx1.cab &endlocal &popd &del /q /f %ddf% &goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement