In GUI, if you use Add to Archive, there will be checkboxes for only .tar and .wim files (I don't understand why they did not do for .zip, .7z and others) :-(
We have to show some creativity. We can create an exclusion file containing all symbolic links. First open Command Prompt and run cd "Folder"
where Folder
is the folder location. Now run dir /al /s /b >exclusions.txt
. The /s
switch is for recursive, you can omit it if not needed. Assuming 7z.exe is in your PATH, then run 7z a "name.7z" "folder\" -xr@exclusions.txt
where "Name" is the archive name and "folder" is the folder name. If 7z.exe is not in PATH, you have to specify the full path.
To make the whole process more flex, you can add a context menu entry:
- First create a batch file with this code:
@echo off
dir /al /b /s %1 >exclusions.txt 2>nul
"C:\Program Files (x86)\7-zip\7z.exe" a "%~na.7z" "%~1\" -xr@exclusions.txt >nul 2>&1
del /f /q exclusions.txt
Note: you can modify the path of 7z.exe.
- Open Registry Editor as Administrator.
- Now go to
HKEY_CLASSES_ROOT\Folder\shell
.
- Create a new key named
Add to archive without symbolic links 7-zip
.
- Then create a subkey named
command
.
- Set the default value of command key to
"Full path of the .bat file" "%1"
.
Then you will find a context menu named "Add to archive without symbolic links 7-zip" when you right click a folder.
By default the archive will be created in current working directory named archive.7z
(7z format). A modified script that will ask you for Archive name and format:
@echo off
dir /al /b /s %1 >exclusions.txt 2>nul
set /p a_name=Enter Archive name:
set /p a_fo=Enter archive format(Without extension):
if "%a_fo:~0,1%"=="." set "a_fo=%a_fo:~1%"
"C:\Program Files (x86)\7-zip\7z.exe" a "%a_name%.%a_fo%" "%~1\" -xr@exclusions.txt >nul 2>&1
del /f /q exclusions.txt
Now to make the script beyond helpful, you can read the help documentation and add the options as you need. I will prepare a GUI solution (using .NET WinForms and Powershell) in a few days.
Another one with auto UAC elevation and context menu creation:
goto="Batch" /*
:Admin
@echo off
reg query "HKEY_CLASSES_ROOT\Folder\shell\Add to archive without symbolic links 7zip" >nul 2>&1
if %errorlevel% equ 1 (
reg add "HKEY_CLASSES_ROOT\Folder\shell\Add to archive without symbolic links 7zip"
reg add "HKEY_CLASSES_ROOT\Folder\shell\Add to archive without symbolic links 7zip\command"
reg add "HKEY_CLASSES_ROOT\Folder\shell\Add to archive without symbolic links 7zip\command" /f /v "(Default)" /t REG_SZ /d "Bat file path %1" %== Replace Bat file path here ==%
)
dir /al /b /s %1 >exclusions.txt 2>nul
set /p a_name=Enter Archive name:
set /p a_fo=Enter archive format(Without extension):
if "%a_fo:~0,1%"=="." set "a_fo=%a_fo:~1%"
"C:\Program Files (x86)\7-zip\7z.exe" a "%a_name%.%a_fo%" "%~1\" -xr@exclusions.txt >nul 2>&1
del /f /q exclusions.txt
exit /b 0
:RunAsAdmin
color 4f & echo Running Admin Shell, Please wait.... & call cscript //nologo /e:JScript "%~f0" RunAsAdmin "%1" & exit /b
:"Batch"
@echo off & setlocal enabledelayedexpansion & cls
openfiles >nul 2>&1 || goto :RunAsAdmin
goto :Admin
:"JScript" */
function RunAsAdmin(self, arguments) { WSH.CreateObject('Shell.Application').ShellExecute(self, arguments, '', 'runas', 1) }
if (WSH.Arguments.length>=1 && WSH.Arguments(0)=='RunAsAdmin') RunAsAdmin(WSH.ScriptFullName,WSH.Arguments(1));
//