7zip SFX Batch For SendTo Folder

爱⌒轻易说出口 提交于 2019-12-07 18:45:08

问题


7z a -mx9 -sfx %1.exe %1

This is what i have so far as a batch file, which if i drag and drop a file or folder onto the batch file i get a 7zip SFX on Ultra Compression under the same name as the original file. but this only works if the file is in the same folder as the batch file.

What im trying to achieve is, putting this batch file into the sendto folder so i can convert any file anywhere into a highly compressed exe, which appear in the folder of the original directory.

Any help would be greatly appreciated, im sure its simple but i haven't a clue.

Edit 29 May @ 16:50

[HKEY_CLASSES_ROOT*\shell\Compress To Exe]

[HKEY_CLASSES_ROOT*\shell\Compress To Exe\command] @="\"c:\Program Files\7-Zip\7z\" u -mx9 -sfx -r -t7z \"%1.exe\" \"%1\""

add that to registry or .reg file to create a context menu button, that's parent to the sendto.


回答1:


I use the following batch file to send a file or a folder to the Send-To shortcut, which creates a self extracting 7z file in the same location as the original file/folder:

@echo off
cd /d %1
if %errorlevel%==1 (goto file) else (goto dir)

:dir
cd..
"c:\Program Files\7-Zip\7z" u -mx9 -sfx -r -t7z "%~n1.exe" "%~f1"
goto :EOF

:file
cd /d "%~dp1"
if exist "%~n1.exe" (
  "c:\Program Files\7-Zip\7z" u -mx9 -sfx -t7z "%~n1_zipped.exe" "%~f1"
) else (
  "c:\Program Files\7-Zip\7z" u -mx9 -sfx -t7z "%~n1.exe" "%~f1"
)
goto :EOF

My parameters are slightly different from yours, but you can tweak them as you like.

May 29 - Edit

Added the if exist code so that if you send an .exe to the batch file, it will still create a self-extracting .exe, but with _zipped in the filename.



来源:https://stackoverflow.com/questions/16795607/7zip-sfx-batch-for-sendto-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!