Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
tweacle
- Posts: 71
- Joined: 11 Apr 2018 05:38
#1
Post
by tweacle » 07 May 2018 04:52
I have the following bat file command that comes up correctly asking me for the password and what i want to name folder of which I input then nothing else happens and it should 7zip it.
Any Ideas.
Code: Select all
]@echo off
cls
SETLOCAL EnableDelayedExpansion
set DL=C:\Users\g\Downloads\test
set /p PW=”Please type password:”
set /p FL=”Please type folder name:”
for /f "tokens=1,2 delims=." %%a in ('dir /b /a-d "!DL!"') do (
set fn=%%a
set fe=%%b
cd !dl!
"C:\Program Files\7-Zip\7z.exe" a -tzip "!fn!.7z" -p!PW! "!fn!.!fe!" '-x!*.7z' -sdel
(
move *.7z !FL!
-
ShadowThief
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
#2
Post
by ShadowThief » 07 May 2018 05:20
Your second to last line is a ( when it should be a )
Honestly, I'm kind of surprised that it doesn't throw an error.
-
Compo
- Posts: 600
- Joined: 21 Mar 2014 08:50
#3
Post
by Compo » 07 May 2018 08:59
You could try it like this:
Code: Select all
@Echo Off
Set "ZE=%ProgramFiles%\7-Zip\7z.exe"
Set "DL=C:\Users\g\Downloads\test"
If Not Exist "%ZE%" Exit /B
CD /D "%DL%" 2>Nul || Exit /B
:GetPW
Set "PW="
Set /P "PW=Please provide an archive password:"
If Not Defined PW GoTo GetPW
:GetFL
Set "FL="
Set /P "FL=Please supply the destination for the archive:"
If Not Defined FL GoTo GetFL
If Not Exist "%FL%\" GoTo GetFL
For %%A In (*) Do "%ZE%" a -tzip "%%~nA.7z" -p%PW% "%%A" -x!*.7z -o"%FL%" -sdel
You should note that although there are some checks built into this, there are none checking for characters in the password which could cause issues when run from cmd.exe in a batch file;
for those those you'll have to find a suitable workaround yourself!