Can anyone help on extending a command.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Can anyone help on extending a command.

#1 Post by tweacle » 15 Apr 2018 05:57

Hi

I have the following command of which at present it looks for a specific folder and then 7 ZIP's it up

7-Zip: 7za a –tzip "archive folder name" "source folder name"

What im trying to do is look in C:/Downloads for any unzipped folders and then zip it asking me for a password too if possible and then saving as a zipped folder in c:/Downloads

If possible too when it creates a new folder can I then automatically delete the UNZIPPED one.

The other issue that I will have there will already be zipped folders in "C/Downloads" so if they are already zipped and password protected I need them left alone and when zipping the folders all the folders will be named differently within C:/Downloads


Any Ideas

Thanks

tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Re: Can anyone help on extending a command.

#2 Post by tweacle » 15 Apr 2018 06:48

I think that I may be complicating things.

Another way I can do it is to set up 7-Zip: 7za a –tzip "C:/Downloads " "C:Downloads" and then move the zipped file to another file called C:/COMPLETED ZIPPED DOWNLOADS but I would still need the password to be input and protected before moving.

I think that would be easier can anyone help on a script for that ?

Thanks

penpen
Expert
Posts: 1992
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Can anyone help on extending a command.

#3 Post by penpen » 15 Apr 2018 07:54

Just use the switch "-p" without setting it and 7-Zip will prompt you for the password:

Code: Select all

"C:\Program Files\7-Zip\7z.exe" a "archive.zip" -m"em=ZipCrypto" "*.txt" -p
For more information use "7z.exe -?" or see:
https://sevenzip.osdn.jp/chm/cmdline/

penpen

tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Re: Can anyone help on extending a command.

#4 Post by tweacle » 15 Apr 2018 10:19

Sorry penpen you confused me. Where do I put that command? its just you saying abut C:/ program files and im talking about C:/ downloads.

All im trying to do it is to set up 7-Zip: 7za a –tzip "C:/Downloads " "C:Downloads" and then move the zipped file to another file called C:/COMPLETED ZIPPED DOWNLOADS but I would still need the password to be input and protected before moving.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Can anyone help on extending a command.

#5 Post by Ed Dyreen » 15 Apr 2018 11:05

tweacle wrote:
15 Apr 2018 10:19
Sorry penpen you confused me. Where do I put that command? its just you saying abut C:/ program files and im talking about C:/ downloads.
"C:\Program Files\7-Zip\7z.exe" is the default location of 7zip, you need 7zip to do anything with it, so you need to tell your program which program to run. that would be "C:\Program Files\7-Zip\7z.exe" by default or whichever directory you installed 7z.exe.
tweacle wrote:
15 Apr 2018 10:19
All im trying to do it is to set up 7-Zip: 7za a –tzip "C:/Downloads " "C:Downloads" and then move the zipped file to another file called C:/COMPLETED ZIPPED DOWNLOADS but I would still need the password to be input and protected before moving.
You say to set up 7za, penpen is talking about 7z.exe these are two different programs ! You don't need to move any zipped files if you tell 7zip to create the archive in the desired directory. Penpen said the -p makes 7zip prompt you for the password, without verifying I assume penpen is correct.

tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Re: Can anyone help on extending a command.

#6 Post by tweacle » 15 Apr 2018 11:30

Got ya

Really sorry as dos things to me are over my head.

Do I copy that txt into a notepad and save as a .exe or .cmd file?

penpen
Expert
Posts: 1992
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Can anyone help on extending a command.

#7 Post by penpen » 15 Apr 2018 16:56

Sorry for confusing you, i had not much time, so i've tried to write short postings.
"7z.exe" and "7za.exe" should share the above options and command line switches, so this should also work (for the actual version):

Code: Select all

7za a "archive.zip" -t"zip" -m"em=ZipCrypto" "*.txt" -p
I'm also unsure if you are using Windows (because you are using a slash instead a backslash in your pathes; for example in "C:/Downloads").

In case you are using windows the following batch script "test.bat" might help you (assuming "7za.exe" could be called directly from your command line; as your OP implies):

Code: Select all

@echo off
for /d %%a in ("C:\Downloads\*") do (
	if not exist "C:\COMPLETED\%%~na.zip" (
		7za.exe a "C:\COMPLETED\%%~na.zip" -t"zip" -m"em=ZipCrypto" "Far" -p
	) else (
		echo(Error cannot zip directory; target zip file name is occupied
	)
)
Note that this batch doesn't delete any files (but you may add it if you want using the "rd" command - if the rest of your script does what you need).
Hope the above does help you.

penpen

Edit: Wrong path; changed 'if not exist "%%~na.zip"' to 'if not exist "C:\COMPLETED\%%~na.zip"'.

tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Re: Can anyone help on extending a command.

#8 Post by tweacle » 16 Apr 2018 04:05

Ive tried that script but I think that I have a problem with my 7 Zip.

Donno if anyone knows but I click on the file command on the desktop and it flashes as if something happening but nothing does.

You all mention 7za but cant find that anywhere in my 7 zip program

penpen
Expert
Posts: 1992
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Can anyone help on extending a command.

#9 Post by penpen » 16 Apr 2018 04:31

I had a bug in my above script, but that should only lead in always creating a zip in your target folder "C:\COMPLETED\" per subfloder in "C:\Downloads\".
But that is not your issue, because you would have been prompted for a password if any folder was zipped.

You should open a command shell ("cmd.exe"), and change the path to your desktop.
After that type in the name of your batch file and hit enter.
You could copy the content of the shell and paste it to your next post (please use code tags around your code):
If "quick edit mode" is not enabled, then first click the right mouse button somewhere at the command shell.
Then (no matter which mode) push down the left mouse button onto a corner of the area you want to mark,
move the mouse until everything you like is marked, and then release the left mouse button and hit the ENTER-key.
Pasting to the post editing area within your browser is done by pressing the combination CTRL+V.

If i have to guess, then i think, that the command shell don't know the path of your 7-Zip standalone executable.
You may add it to my above script; make sure you use default doublequotes around the complete path if the path contains any space characters - should look similar to my first reply.

penpen

tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Re: Can anyone help on extending a command.

#10 Post by tweacle » 16 Apr 2018 04:38

PenPen I get this come up...

C:\Users\g\Desktop>7za a "archive.zip" -t"zip" -m"em=ZipCrypto" "*.txt" -p
'7za' is not recognized as an internal or external command,
operable program or batch file.

penpen
Expert
Posts: 1992
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Can anyone help on extending a command.

#11 Post by penpen » 16 Apr 2018 14:16

Then you have to add the path to '7za'; if "7za.exe" is in folder "C:\foo\doo", then you have to use "C:\foo\doo\7za.exe".

penpen

tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Re: Can anyone help on extending a command.

#12 Post by tweacle » 17 Apr 2018 03:46

Ladies and Gents

My sincere apologies but its all above my head now as far as writing scripts etc.

I have the following script below that does what it needs to but what I need to do is after the folder has been merged I need to 7zip the folder and password protect.

Would anyone be able to write me a script please please.

Thanks

Code: Select all

Option Explicit

Const strDLFolder = "C:\Downloads"
Dim objFSO, objWShell, objDLFolder, strNewFolder, objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWShell = CreateObject("WScript.Shell")


If Not objFSO.FolderExists(strDLFolder) Then objFSO.CreateFolder(strDLFolder)
objWShell.CurrentDirectory = strDLFolder
Set objDLFolder = objFSO.GetFolder(strDLFolder)
If objDLFolder.Files.Count = 0 Then WScript.Quit

Do
  Err.Clear
  strNewFolder = InputBox("Folder Name", vbLf & "Enter the name of the folder to be created:")
  If strNewFolder = False Then WScript.Quit
  On Error Resume Next
  objFSO.CreateFolder strNewFolder
Loop While Err.Number <> 0 Or Not objFSO.FolderExists(strNewFolder)

On Error Goto 0
For Each objFile In objDLFolder.Files
  objFSO.MoveFile objFile.Name, strNewFolder & "\"
Next

objWShell.Popup "All files moved.", 0, "Done", vbInformation Or vbSystemModal Or &h00040000&
Last edited by Squashman on 17 Apr 2018 06:11, edited 1 time in total.
Reason: MOD EDIT: Please use code tags.

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: Can anyone help on extending a command.

#13 Post by Squashman » 17 Apr 2018 06:13

Why the switch to VBscript?

tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Re: Can anyone help on extending a command.

#14 Post by tweacle » 17 Apr 2018 09:42

Dont have to be a VB script. Anyway dont matter if that helps. its just what I posted was a VB script and thought that the only way.

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: Can anyone help on extending a command.

#15 Post by Squashman » 17 Apr 2018 19:35

You have already been shown how to zip the folder and password protect the folder. What are you not understanding from the previous help you have been given.

Post Reply