How do I sort a MSDOS/ VBS command out?

April 27, 2018 at 11:58:48
Specs: Windows 7
Hi

Ive sort of got my head round what I need to do but need one or two minor adjustments made as I dont know where they go as im totally confused with .msdos/ VBA unless written out for me.

Please dont think im being lazy as im not I am honestly completely new to this and donno where to start.

I have the following .MSDOS and .VBA script that creates a folder & zips it

What I need to do in addition is the following.

1) When it puts it into a folder I need it to ask me to input a password . When password input I then need it to move onto the .VBA command of zipping

2) What I also need is instead of it just creating a 7Z file with the name of zipped.7z I need it to be the same name as what the folder was called originally.
I was advised of some code like this but aint got a clue on what it is or where it to go in script.

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".

CAN I MAKE ONE BIG BIG PLEA AND CAN YOU POSSIBLY AMEND MY SCRIPT BELOW AND JUST REPOST FOR ME PLEASE PLEASE :'(


ORIGINAL SCRIPTS BELOW

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\icc.cctv\Documents\DONOTDELETE1.bat", 1, True
set dotbat=Nothing

@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


big big thanks in advance

message edited by GDB


See More: How do I sort a MSDOS/ VBS command out?

Report •

#1
April 27, 2018 at 23:57:10
Don't have the time.

Report •

#2
April 28, 2018 at 00:40:18
Thanks anyway Phil. Anyone else can assist?

Report •

#3
April 28, 2018 at 21:15:14
I suggest to start from scratch. The script(s) look all mangled to me and a lot of useless code.
"I was advised of some code like this but aint got a clue on what it is or where it to go in script."
You and me both!
Here's my take, for you to elaborate or correct:
1) move files from a download directory to a user-specified directory-name
2) zip all the files with user-provided password using 7z

1) what is "donotdelete.bat" content? (I really don't care, but you should have posted it)
2) Nowhere is 7z option -p (which sets the encryption password) mentioned in your 7z commandline

Nine times out of ten, when folks drag stuff off google or internet, they spend a thousand times more effort trying to adapt the imported code to their use than would be if it were approached from ground-up.
I don't know why, but you probly have your reasons, for using a combo of vbs / vba and bartch. Usually it's better to stick with one or the other or at least minimize one of them.
If you come back with some specific details of your objectives, maybe you can eventually, with some assist, achieve them.


Report •

Related Solutions

#4
April 29, 2018 at 01:18:51
Agree nbrane. Im just totally confused so let me post below what im trying to do....


Im trying to create a script so that I can get it to create a folder in C:\Downloads and ask me to name the folder and then move the files that are also in C:\Downloads into the folder.
I then need a message box or something to pop up asking if I have attached statement and if answer is "YES" I need it to carry on and if "NO" I need it to advise me with a message stating "attach the statement in folder and rerun command" and after 10 secs close the command.

If answer is "YES" I need it to ask me to input a password for the folder and then zip the folder. I have 7zip or windows one but NOT win zip.
Finally after the folder zipped I need it to ask me if I want to move the files to A) AAA DOWNLOADS or B) BBB DOWNLOADS and select which one.
Once selected I need it moved to the one I advised I wanted it moved to.

What I also need if poss when zipped I need it to keep the folder name for the zipped folder that I created the same as the one I named before zipping.

AAA downloads to save to C:\Mydocuments\AAA DOWLOADS
BBB downloads to save to C:\Mydocuments\BBB DOWLOADS

The original UNZIPPED folder I always need moved to C:\Mydocuments\CCC DOWLOADS once zipped file moved into AAA or BBB downloads.

Any help greatly appriciated. Ive got a cheek but if its only amending the text below is there any chance you could just copy and paste.

Big Big thanks in advance

Original script 


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

@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[/QUOTE]


Report •

#5
April 29, 2018 at 20:43:29
Here's the basics, using batch only:

@echo off & setlocal
pushd "c:\my documents\downloads"
:: set up the path to your 7z.exe, unless it's in the default chain:
set zip=c:\xxx\whatever\7z.exe
:next
set x=
set y=
set p=
set /p x=directory to zip:
if not defined x goto :eof
set /p y=destination directory:
if not defined y goto :eof
set /p p=encryption password:
if defined p set p=-p%p%
%zip% a %p% %y%\%x%. %x%
move %x% CCC
goto :next
:: end batch-script

In my tests this worked. destination directory does not need to pre-exist.

If you want GUI, maybe we can start from here and work up, instead of the other way around. You never really said if you need this to be "user friendly" (ie: desktop icons or "dumbed down") for end-users or just for your own use. Big difference in presentation but not mechanics. All that crud-ola about STATEMENT appears to be making sure that 7z is accessible and executable. All you need to do is make sure to put the full path to 7z into the %zip% variable OR make sure 7z.exe is somewhere in your default path. If you want icons and popup prompts, we can work on that.

message edited by nbrane


Report •

#6
April 30, 2018 at 02:51:29
Many thanks but I think im just being stupid as it not working for me .

I will show you what I done and saved as a .BAT file

This is what ive done in italics

@echo off & setlocal
pushd "c:\my documents\downloads"
:: set up the path to your 7z.exe, unless it's in the default chain:
set zip=c:\program files\7-Zip\7z.exe
:next
set x=
set y=
set p=
set /p x=directory to zip:
if not defined x goto :eof
set /p y=destination directory:
if not defined y goto :eof
set /p p=encryption password:
if defined p set p=-p%p%
%zip% a %p% %y%\%x%. %x%
move %x% CCC
goto :next
:: end batch-script

There is probably something Ive missed at the bottom but aint got a clue what to put in.



Report •

#7
April 30, 2018 at 18:48:33
I don't know what you're seeing on your end. Any err-msg?
Try running with echo ON, and come back with a screen-cap or at least a good rendition thereof. Turn echo ON like this (leaving the 'setlocal' active):
rem @echo on
setlocal

Since it worked in my local tests, I need to see where it's failing on your end.
Be sure to include what you answered to the prompts, esp. for source and dest directories. Work on the password later after fixing this, (hopefully).

Here's a screen-cap of my tests (batch is gdb.bat of course):

C:\work>gdb
directory to zip:temp
destination directory:tempxxx
encryption password:test

7-Zip 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
Scanning

Creating archive tempxxx\temp

Compressing temp\o.zip
Compressing temp\AUTOCLEA.BAT
Compressing temp\INFECTED.BAT
Compressing temp\MONITOR_.BAT
Compressing temp\MBAR-LOG.TXT
Compressing temp\MYLOG.TXT

Everything is Ok
directory to zip:

(Here, I entered a nul [ENTER], which exits the batch)

C:\work>dir tempxxx
Volume in drive C has no label.
Volume Serial Number is CA55-4799

Directory of C:\work\tempxxx

04/30/2018 09:56 PM <DIR> .
04/30/2018 09:56 PM <DIR> ..
04/30/2018 09:56 PM 48,003 temp
1 File(s) 48,003 bytes
2 Dir(s) 2,776,981,504 bytes free


C:\work>cd tempxxx

C:\work\tempxxx>7z L temp

C:\work\tempxxx>c:\comands\7-zip\7z L temp

7-Zip 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18

Listing archive: temp

--
Path = temp
Type = 7z
Method = LZMA 7zAES
Solid = +
Blocks = 1
Physical Size = 48003
Headers Size = 323

Date Time Attr Size Compressed Name
------------------- ----- ------------ ------------ ------------------------
2015-11-26 23:29:02 ....A 26333 47680 temp\o.zip
2015-11-27 02:55:52 ....A 84324 temp\AUTOCLEA.BAT
2015-11-27 01:18:38 ....A 3169 temp\INFECTED.BAT
2015-11-27 03:33:00 ....A 12421 temp\MONITOR_.BAT
2015-11-27 01:52:00 ....A 2048 temp\MBAR-LOG.TXT
2015-11-26 23:31:50 ....A 2093 temp\MYLOG.TXT
2018-04-30 21:56:30 D.... 0 0 temp
------------------- ----- ------------ ------------ ------------------------
130388 47680 6 files, 1 folders

message edited by nbrane


Report •

#8
May 1, 2018 at 00:34:52
Got a slight prob with 7 zip at mo and sorting otherwise sorted. Ta

Report •

Ask Question