To make it work for 7z format, make following changes:Ĭhange target file name set DestZip=D:\Destinationtest\BACKUP.7zĮdit last line "%SevenZip%" a -mhe=on -pYourPassword "%DestZip%" -r "%BaseDir%\*.*"Īfter these changes, it will ask for password every time. But this option does not work with zip format. To encrypt file name, you need to add -mhe=on option to encrypt file header. I have a zipfile in (sav.zip) and Im trying to set a password for it: zf zipfile.ZipFile('sav.zip') zf.setpassword('1234') but I get a TypeError: expected Bytes, got str. When I try to extract output file, it asks for password: Chris at 17:30 try this zf.setpassword (b'1234'), basically password param should be bytes instead of string. Set VarA=%%a&set VarB=%%b&set VarC=%%c&set VarD=%%d&set VarE=%%e&set VarF=%%f&set VarG=%%g&set VarH=%%h&set VarI=%%i 4 Answers Sorted by: 40 By nature if you want the file to be encrypted, it needs to be unpacked and repacked, since the whole archive needs to be encrypted with the password. 119k 25 164 294 asked at 17:26 user7875282 4 Please read the documentation for tpassword (). REM Zip all files and folders echo Getting time. "%SevenZip%" a -pYourPassword -tzip "%DestZip%" -r "%BaseDir%\*.*" This is the point where you can add -p option. Last line of this batch file is responsible to execute 7z command line. It would have been easier for you if batch file was formatted properly. Set TimeStamp=%Year%%Month%%Day%_%Hour%%Minute%%Second%įor %%a in ("%DestZip%") do (set DestZip=%%~dpna-%TimeStamp%%%~xa) Set SevenZip=C:\Program Files\7-Zip\7z.exeįor /f "tokens=1-9" %%a in ('wmic.exe Path Win32_LocalTime Get Day^,DayOfWeek^,Hour^,Minute^,Month^,Quarter^,Second^,WeekInMonth^,Year ^| find /v ""') do ( Set DestZip=D:\Destinationtest\BACKUP.zip Any idea where do I put the -p command to make it work? I tried but it is not working for me. I have a script below which is working perfectly, all I need is to add a password & encryption while compressing.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |