Solved Can anyone help in finishing off a batch file

April 22, 2018 at 04:38:55
Specs: Windows 7
Hi

I have the following batch file command of which I think is correct as just got off you tube.

@echo off
:start
cls
echo MAKE SURE YOU HAVE ENTERED
echo STATEMENT INTO FOLDER BEFORE
echo CONTINUING
echo1. DONE IT
echo2. FORGOT IT
choice /c12 your choice
if errorlevel 1 goto exit
if errorlevel 2 goto continue


:continue
cd\program files\7-zip
7z a -t7z "C:\Downloads\zipped.7z" "C:\Downloads"

:exit
exit

What in trying to do is to be able to get that into a .vbs if im right? and to be able to click on a shortcut and it runs depending if 1 or 2 pushed it does it,

I cant get it to save as a vbs and I also think I do not have a command to open DOS in :continue bit.

Can anyone possibly adjust for me so I can just click on a icon and it run.

Big Thanks


See More: Can anyone help in finishing off a batch file

Report •

✔ Best Answer
April 24, 2018 at 02:09:07
Create a shortcut to this .bat file(you can place the .bat file anywhere) & place it on the desktop.
I've tried to make it a bit more readable than what i would normally do.
Dont forget to make a backup of the files, as i have no clue what the 7z command does, haha.


::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

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-13-13-28 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.25v/1915MHz memory@1.0v BiosModded



#1
April 22, 2018 at 05:03:06
what is the statement?
just make a .vbs that runs your .bat in the background
let the .bat handle the if statement & exit if it doesnt exist.
that way you can remove this part:
"
echo MAKE SURE YOU HAVE ENTERED
echo STATEMENT INTO FOLDER BEFORE
echo CONTINUING
echo.
echo [1] DONE IT
echo [2] FORGOT IT
choice /c 12 /n>nul
"
& are you sure your Download folder is located here:"C:\Downloads"
instead of here: "%USERPROFILE%\Downloads"
"%userprofile%" stands for "C:\Users\%USERNAME%"

also i changed some stuff:


@echo off
cls
echo MAKE SURE YOU HAVE ENTERED
echo STATEMENT INTO FOLDER BEFORE
echo CONTINUING
echo.
echo [1] DONE IT
echo [2] FORGOT IT
choice /c 12 /n>nul
if %errorlevel%==2 exit/b
::this is a comment: if errorlevel aint 2, so its 1 do the below
PUSHD "%PROGRAMFILES%\7-zip"
7z a -t7z "C:\Downloads\zipped.7z" "C:\Downloads"


i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-30 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.25v/1920MHz memory@1.0v BiosModded

message edited by hidde663


Report •

#2
April 22, 2018 at 05:17:31
Let me apologise first but this is all over top of my head so it need to be idiot proof.

When you say you need to know statement you mean what I wanna do?

I have a folder "C\DOWNLOADS" and I need to be able to click on the icon and then come up with 2 options and if statement included and "yes " pressed I need it to open MS-DOS and then do this

cd\program files\7-zip
7z a -t7z "C:\Downloads\zipped.7z" "C:\Downloads"

obviously if "NO" I dont wanna it to do it.


Report •

#3
April 22, 2018 at 05:40:43
the below statement you are refering to multiple times but not saying what it is:

echo MAKE SURE YOU HAVE ENTERED
echo STATEMENT INTO FOLDER BEFORE

and if statement included and "yes " pressed I need it to open MS-DOS and then do this

im asking because i want to automate this for you, no need for clicking 1 or 2
i want the hidden .bat file to check it for you & do or NOT do it

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-30 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.25v/1920MHz memory@1.0v BiosModded


Report •

Related Solutions

#4
April 22, 2018 at 10:04:48
hidde663

What you had done in the first post was absolutely spot on. Many Thanks.

What you said about automatically checking I wouldnt be able to check that automatically I dont think as it will be a PDF file and will always have a different name as its a statement

Ive got a big favour to ask.

If I push no 1 it zips it as it should do of which is brill but can I do the following after if poss.

1) when it all zipped up a message appears somewhere stating that all the files are zipped up and completed as dos screen just disappearing would confuse some people who use it.

2) Can I get some sort of command before or after zipping asking me what the name of the zipped file is going to be called as im going to be zipping loads of files seperately but keep them in C:\Downloads.

If its after zipping up I then will need something for it to continue after the message appears that they are zipped. something like press any key to continue.

3) If I push no 2 can I get a message appear to say "please attach statement and re run command clicking on icon on desktop"

Big Big Thanks for so far.


Report •

#5
April 22, 2018 at 13:53:58
1) yes you can; i can make the .bat check the tasklist for any running 7zip.exe's & tell te user it is done when 7z closes.

2)yes, but this may take me some time to figure out, as i have no experience with 7zip, but im sure i can find a way to do it

3)yes, ill make it say ENTER THE STATEMENT INTO FOLDER
& timeout for 5seconds then close the dos window

PS dont expect me to be done with it before Tuesday afternoon, since i do not have much time right now

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-13-13-28 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.225v/1915MHz memory@1.0v BiosModded


Report •

#6
April 22, 2018 at 14:07:46
thats absolutely fine thanks


Report •

#7
April 24, 2018 at 02:09:07
✔ Best Answer
Create a shortcut to this .bat file(you can place the .bat file anywhere) & place it on the desktop.
I've tried to make it a bit more readable than what i would normally do.
Dont forget to make a backup of the files, as i have no clue what the 7z command does, haha.


::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

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-13-13-28 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.25v/1915MHz memory@1.0v BiosModded


Report •

#8
April 24, 2018 at 03:18:44
hidde663 thats brill and really appreciate all your help. ..

Only thing I found was it was not deleting files that had been zipped into a 7z folder.

Can I ask you if you can merge .VBS and .BAT files together or change the commands into 1 type of file?

It just got a different idea with your previous post and I think would be a lot easier.

I have the following .VBS file

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&


and then your command you gave me as you posted above.


Is there any way that it can run the first one to make the folder move it all and the message box " all files moved" appear and then when you push OK it then it come up with your MS DOS command asking if statement attached and then carry on .

I see that you put the MS DOS command to run invisible in the background. Sorry to be a pain but I prefer it to be showing running as then you can see its doing something as people who going to use this if they dont see nothing happening they will stop or turn PC off.

One final thing when a file has been zipped previously but still in C:\Downloads are you able to set up a command in the script to ignore that file and just 7 zip the unzipped ones?

Big Thanks in advance


Report •

#9
April 24, 2018 at 03:52:51
Can I ask you if you can merge .VBS and .BAT files together or change the commands into 1 type of file?

-I could merge them, but it would end up making the .bat from within the .vbs anyways so i do not really see a point in doing that

I see that you put the MS DOS command to run invisible in the background

- only the 7zip part

One final thing when a file has been zipped previously but still in C:\Downloads are you able to set up a command in the script to ignore that file and just 7 zip the unzipped ones?

-i actually have no clue, like i previousely states; i have no experience using winzip,winrar or 7zip command line arguments


this would be the .bat without the invisible part;

@echo off&PUSHD "%PROGRAMFILES%\7-zip"&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
if '%errorlevel%'=='2' (
cls&echo ENTER THE STATEMENT INTO FOLDER,
echo THIS WINDOW WILL CLOSE IN 5 SEC.
) else (
cls
7z a -t7z "C:\Downloads\zipped.7z" "C:\Downloads"
echo.&echo ALL FILES MOVED^^!
)
timeout 5 /NOBREAK >nul&exit/b

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-13-13-28 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.25v/1915MHz memory@1.0v BiosModded

message edited by hidde663


Report •

#10
April 24, 2018 at 04:01:37
Thats fine many many thanks.

The only reason I wanted to merge the .BAT withing the .VBS was so that I click on 1 icon only and the whole lot run.

If I could do that it would be brill.

I will just move the folder when done somewhere else.


message edited by GDB


Report •

#11
April 24, 2018 at 04:11:23
you could add something like this to your .vbs

dim dotbat
set dotbat=createobject("wscript.shell")
dotbat.run="C:\place_you_want_to_save_it\dotbatfilename.bat"
set dotbat=nothing

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-13-13-28 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.25v/1915MHz memory@1.0v BiosModded


Report •

#12
April 24, 2018 at 08:13:09
Im probably doing something wrong but can I just check something.

Ive got as stated the additional item in as shown below added to the .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:\Downloads\CCTV\dotbatfilename.bat"
set dotbat=nothing

but keep getting

Line 32
Char 1
Object does not support this property or method :"run"
Code 800A01B6
Microsoft VB Script runtime error

Is it correct at the end of the script?


This line
dotbat.run="C:\place_you_want_to_save_it\dotbatfilename.bat"
Do I have to input where I wanna save the file to or where the .BAT file is located?

Thanks



Report •

#13
April 24, 2018 at 08:24:30
try changing it to:

dotbat.Run "%comspec% /K "C:\Downloads\CCTV\dotbatfilename.bat", 1, True

if that also doesnt work try:

dotbat.Run "C:\Downloads\CCTV\dotbatfilename.bat", 1, True

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-13-13-28 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.25v/1915MHz memory@1.0v BiosModded

message edited by hidde663


Report •

#14
April 24, 2018 at 10:21:13
Really sorry but im obviously doing something wrong cos i keep getting errors

800A01F4

Just to get it clear in my head I add this command to the end of the .VBS and I need to where it says
dotbatfilename.bat I put the dotbatfilename in ending .VBS

dotbat.Run "C:\Downloads\CCTV\dotbatfilename.bat", 1, True

Ive moved the location where the .bat file is now to desktop so I assume that it will be like this

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

Testers new being the .bat name.


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&


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



Report •

#15
April 25, 2018 at 02:43:14
you removed the lines that make the variable dotbat&create the object Wscript.shell, haha

im still not sure about this line:
dotbat.Run "C:\Desktop\testersnew.bat", 1, True

That is because i do not really code using vbscript, so you may want to look it up

Anyways, your entire .vbs code:

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:\Desktop\testersnew.bat", 1, True
set dotbat=Nothing

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-13-13-28 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.25v/1915MHz memory@1.0v BiosModded


Report •

#16
April 25, 2018 at 20:51:18
My limited experience is that to execute a .bat from vbs you need to put into a cmd
instead of:
dotbat.Run "C:\Desktop\testersnew.bat", 1, True

try:
dotbat.Run "cmd /C C:\Desktop\testersnew.bat", 1, True

(hide hit on this with %comspec% in post 13 but don't know why it didn't work)
the only way I know to communicate from the .bat back to the parent (vbs) is by using a file. The errorlevel returned by CMD will probably be zero regardless of the batch outcome, and of course "global" vars from child process will not reflect back.
google: script56.chm
for downloadable vbs help file - it has helped me immensely.

message edited by nbrane


Report •

Ask Question