An apology and one final question to clear a matter up

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

An apology and one final question to clear a matter up

#1 Post by tweacle » 27 Apr 2018 04:44

Ladies and Gents

I have seen comments on here regarding mutiple posts being duplicated by me. I apologise for that and can I explain that I get confused and the only way I can get my head round it is to ask in a different way. :( :(

Im order to clear this up once and for all can I ask a final questions that will finish my posting and annoying you all. :?: :?:

I have the following .VBS

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&

dim dotbat
set dotbat=createobject("wscript.shell")
dotbat.Run "C:\Users\g\Desktop\testersnew.bat", 1, True
set dotbat=Nothing

and the following .BAT File

::start-of-7zipped.bat
@echo off
::goto directory %TEMP%, since this is where this file will make 2 more files
pushd "%TEMP%"
cls
echo MAKE SURE YOU HAVE ENTERED
echo STATEMENT INTO FOLDER BEFORE
echo CONTINUING^^!
echo.
echo [1] I'VE DONE THAT
echo [2] I'VE FORGOTTEN THAT
choice /c 12 /n>nul
::this is a comment: if errorlevel aint 2, so its 1 do the below
if %errorlevel%==2 (
cls
echo ENTER THE STATEMENT INTO FOLDER,
echo THIS WINDOW WILL CLOSE IN 5 SEC.
timeout 5 /NOBREAK >nul
exit/b
)
call :Create-zipit-bat
call :Create-invisible-vbs
call :Zippit
::program exists here
exit/b
::below are subroutines
:Create-zipit-bat
::creates zipit.bat if it does not exist, "you" are currently in directory "%TEMP%"
if not exist "zipit.bat" (
echo 7z a -t7z "C:\Downloads\zipped.7z" "C:\Downloads">"zipit.bat"
)
exit/b
:Create-invisible-vbs
::creates invisible.vbs if it does not exist, "you" are currently in directory "%TEMP%"
if not exist "invisible.vbs" (
echo CreateObject^("Wscript.Shell"^).Run """" ^& WScript.Arguments^(0^) ^& """", 0, False>"invisible.vbs"
)
exit/b
:Zippit
::jump to directory "the below..."
PUSHD "%PROGRAMFILES%\7-zip"
::run your 7zip command line, in the background using a .bat hidden witin a .vbs
wscript.exe "%TEMP%\invisible.vbs" "%TEMP%\zipit.bat"
exit/b
::end-of-7zipped.bat

It creates a folder asking me to name the folder before moving the files of which it does fine. It should then move to .DOS asking me if "ive entered the statement" If I push "YES" it should 7zip the file and saves as zipped .7z .

Im obviously put something in wrong as its not doing that . Is there any way I can sort that out?

Can I also ask if it can be amended and resposted complete on here to avoid any further questions so I can just copy and paste with the following also :-

1) I need it to create a folder and .7zip as it does now but need the following too.

2) When it goes to .7ZIP can I get to name the folder with the same name that was used originally to make the folder instead of saving as a folder called zipped.7z ??
3) when I have created the .7zip folder I need to password protect it.
3) After I 7 zipped 1 folder and have it named can I set it up so that I can .7ZIP another folder that is NOT ZIPPED and ignore all the other folders in the folder.


If 7 zip is too difficult that fine just use the windows zip as long as I can password protect folder after zipping. I not got winzip but would winrar do it provided it not a trial download version.

I would really appriciate this .

Thanks in advance

Tweacle

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

Re: An apology and one final question to clear a matter up

#2 Post by penpen » 27 Apr 2018 06:47

tweacle wrote:
27 Apr 2018 04:44
2) When it goes to .7ZIP can I get to name the folder with the same name that was used originally to make the folder instead of saving as a folder called zipped.7z ??
You might call the batch file with a command line argumend, and access it using %1 to %9 (with the same variable modifiers as for variables) and also shift, if you need more).
"exampel.bat":

Code: Select all

@echo off
echo(The first command line argument is "%~1".

Code: Select all

Z:\>example.bat "argA" "argB"
The first command line argument is "argA".
tweacle wrote:
27 Apr 2018 04:44
3) when I have created the .7zip folder I need to password protect it.
3) After I 7 zipped 1 folder and have it named can I set it up so that I can .7ZIP another folder that is NOT ZIPPED and ignore all the other folders in the folder.
It's not possible to set a password after zipped file is created; you have to set the password when creating the zipped file.
I have shown you how to do it here; which ignores all the other folder in the "C:\Downloads" folder:
viewtopic.php?f=3&t=8502&start=15#p56435.
tweacle wrote:
27 Apr 2018 04:44
If 7 zip is too difficult that fine just use the windows zip as long as I can password protect folder after zipping. I not got winzip but would winrar do it provided it not a trial download version.
7zip hasn't implemented to set the password after the file is created, this program has to unzip all files and rezip them.
Winzip and Winrar also do rebuild the zip file in such a case, but because you are compressing the files, you save 50% of the time if you set the password at the first compression pass.


penpen

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

Re: An apology and one final question to clear a matter up

#3 Post by Squashman » 27 Apr 2018 08:19

I see you have decided to still ignore my repeated requests for you to use [CODE][/CODE] tags with your posts.

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

Re: An apology and one final question to clear a matter up

#4 Post by tweacle » 27 Apr 2018 09:50

SORRY but I aint got a clue what you on about...

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: An apology and one final question to clear a matter up

#5 Post by ShadowThief » 27 Apr 2018 11:06

He's asking that you please edit your post, highlight your code, and press this button:
Image

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

Re: An apology and one final question to clear a matter up

#6 Post by tweacle » 27 Apr 2018 11:09

aaaahhh right thanks shadow thief whyu couldnt he just explain that?

IcarusLives
Posts: 181
Joined: 17 Jan 2016 23:55

Re: An apology and one final question to clear a matter up

#7 Post by IcarusLives » 27 Apr 2018 11:24

Probably because it's more trivial than your initial problem. I assume he figured you could handle it..

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

Re: An apology and one final question to clear a matter up

#8 Post by tweacle » 27 Apr 2018 11:31

Probably.

All im trying to is trying to find out where I put the text in that PEN PEN advised on,,

Code: Select all

@echo off
echo(The first command line argument is "%~1".

Code: Select all

Z:\>example.bat "argA" "argB"
The first command line argument is "argA
All im asking if someone could put into the script below and repost.

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&

dim dotbat
set dotbat=createobject("wscript.shell")
dotbat.Run "C:\Users\g\Desktop\testersnew.bat", 1, True
set dotbat=Nothing

and the following .BAT File

::start-of-7zipped.bat
@echo off
::goto directory %TEMP%, since this is where this file will make 2 more files
pushd "%TEMP%"
cls
echo MAKE SURE YOU HAVE ENTERED
echo STATEMENT INTO FOLDER BEFORE
echo CONTINUING^^!
echo.
echo [1] I'VE DONE THAT
echo [2] I'VE FORGOTTEN THAT
choice /c 12 /n>nul
::this is a comment: if errorlevel aint 2, so its 1 do the below
if %errorlevel%==2 (
cls
echo ENTER THE STATEMENT INTO FOLDER,
echo THIS WINDOW WILL CLOSE IN 5 SEC.
timeout 5 /NOBREAK >nul
exit/b
)
call :Create-zipit-bat
call :Create-invisible-vbs
call :Zippit
::program exists here
exit/b
::below are subroutines
:Create-zipit-bat
::creates zipit.bat if it does not exist, "you" are currently in directory "%TEMP%"
if not exist "zipit.bat" (
echo 7z a -t7z "C:\Downloads\zipped.7z" "C:\Downloads">"zipit.bat"
)
exit/b
:Create-invisible-vbs
::creates invisible.vbs if it does not exist, "you" are currently in directory "%TEMP%"
if not exist "invisible.vbs" (
echo CreateObject^("Wscript.Shell"^).Run """" ^& WScript.Arguments^(0^) ^& """", 0, False>"invisible.vbs"
)
exit/b
:Zippit
::jump to directory "the below..."
PUSHD "%PROGRAMFILES%\7-zip"
::run your 7zip command line, in the background using a .bat hidden witin a .vbs
wscript.exe "%TEMP%\invisible.vbs" "%TEMP%\zipit.bat"
exit/b
::end-of-7zipped.bat
Big Thanks

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

Re: An apology and one final question to clear a matter up

#9 Post by Squashman » 27 Apr 2018 12:16

tweacle wrote:
27 Apr 2018 11:09
aaaahhh right thanks shadow thief whyu couldnt he just explain that?
I explained it to you in several private messages to you. Don't play that game with me.

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

Re: An apology and one final question to clear a matter up

#10 Post by tweacle » 27 Apr 2018 12:19

OK I apologised to you and I dont want to get into the game you told me i told you...

All I meed is an answer to my question and thats it matter over

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

Re: An apology and one final question to clear a matter up

#11 Post by Squashman » 27 Apr 2018 14:00

tweacle wrote:
27 Apr 2018 12:19
All I meed is an answer to my question and thats it matter over
We have been trying to lead the horse to water in all of questions you have started but no matter how any of us try to explain something, you do not seem to comprehend.

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

Re: An apology and one final question to clear a matter up

#12 Post by tweacle » 27 Apr 2018 14:45

OK

Can I just finish this off with one simple thing and thats copy and paste from an expert and all over and then I can copy and paste too and finished

I fully understand there are lazy people who post on forums to get stuff done for them but as I explained I aint got a clue on MS.DOS and need stuff explained idiot proof. I am most def not a lazy person.

All I need is what PEN PEN has been posted put into this and thats it all over I do not have a clue where it goes or what command is. PEN PEN POST SHOWN AT BOTTOM

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&

dim dotbat
set dotbat=createobject("wscript.shell")
dotbat.Run "C:\Users\g\Desktop\testersnew.bat", 1, True
set dotbat=Nothing
and the following .BAT File

Code: Select all

::start-of-7zipped.bat
@echo off
::goto directory %TEMP%, since this is where this file will make 2 more files
pushd "%TEMP%"
cls
echo MAKE SURE YOU HAVE ENTERED
echo STATEMENT INTO FOLDER BEFORE
echo CONTINUING^^!
echo.
echo [1] I'VE DONE THAT
echo [2] I'VE FORGOTTEN THAT
choice /c 12 /n>nul
::this is a comment: if errorlevel aint 2, so its 1 do the below
if %errorlevel%==2 (
cls
echo ENTER THE STATEMENT INTO FOLDER,
echo THIS WINDOW WILL CLOSE IN 5 SEC.
timeout 5 /NOBREAK >nul
exit/b
)
call :Create-zipit-bat
call :Create-invisible-vbs
call :Zippit
::program exists here
exit/b
::below are subroutines
:Create-zipit-bat
::creates zipit.bat if it does not exist, "you" are currently in directory "%TEMP%"
if not exist "zipit.bat" (
echo 7z a -t7z "C:\Downloads\zipped.7z" "C:\Downloads">"zipit.bat"
)
exit/b
:Create-invisible-vbs
::creates invisible.vbs if it does not exist, "you" are currently in directory "%TEMP%"
if not exist "invisible.vbs" (
echo CreateObject^("Wscript.Shell"^).Run """" ^& WScript.Arguments^(0^) ^& """", 0, False>"invisible.vbs"
)
exit/b

Code: Select all

PEN PEN POST
@echo off
echo(The first command line argument is "%~1".

Code: Select all

Z:\>example.bat "argA" "argB"
The first command line argument is "argA

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

Re: An apology and one final question to clear a matter up

#13 Post by penpen » 29 Apr 2018 11:56

If i don't error, then you are using the ".VBS script" to defne the "name of the folder", so you have to use a command line argument when calling the batch ("testersnew.bat"), so change the line

Code: Select all

dotbat.Run "C:\Users\g\Desktop\testersnew.bat", 1, True
to:

Code: Select all

dotbat.Run "C:\Users\g\Desktop\testersnew.bat """ & strDLFolder & "\" &  strNewFolder & """", 1, True
Sidenote:
It's a bit irritating, that the first line of the "testersnew.bat" seems to be

Code: Select all

::start-of-7zipped.bat
Then you create "zipit.bat", which seems to be meant as fixed code (you don't change it if it exists), so you have to must also pass use the name of the folder to this batch file as a command line argument; you also must change the name "zipped.7z" to the passed name "%~f1", and so on.

I don't see the benefit in a batch ("testersnew.bat") file creating a batch file ("zipit.bat") which is called by a vbs file ("invisible.vbs") which is also created within the same original batch file ("testersnew.bat"), when you simply could execute this line in your initial vbs script (instead of calling the "testersnew.bat"; escape the doublequotes within a vbs by two doublequotes):

Code: Select all

7z a -t7z "C:\Downloads\zipped.7z" "C:\Downloads"
Sidenote:
I have given you such a script earlier (just replace the 7zip line to the one you need):

Code: Select all

https://www.dostips.com/forum/viewtopic.php?f=3&t=8502&start=15#p56427
penpen

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

Re: An apology and one final question to clear a matter up

#14 Post by tweacle » 29 Apr 2018 13:42

Thanks Pen Pen

Post Reply