Link to home
Start Free TrialLog in
Avatar of ExpExchHelp
ExpExchHelpFlag for United States of America

asked on

Batch file

Hello Experts:

EE expert chaau posted a great VBS script which allows to zip up a folder structure and then move the newly created zip to a specified directory.

His recommended code (which works great btw) is posted below:

*****************

Const FOF_CREATEPROGRESSDLG = &H0&

Const MyZip = "c:\MyFolder\Test.zip"

Const File1 = "c:\Mainfolder_XYZ\"


'-------------- create empty zip file ---------

'Create the basis of a zip file.
CreateObject("Scripting.FileSystemObject") _
.CreateTextFile(MyZip, True) _
.Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)


'-------------- zip ---------------------------

'get ready to add files to zip
'
Dim oShell
Set oShell = CreateObject("Shell.Application")

'add files
oShell.NameSpace(MyZip).CopyHere oShell.NameSpace(File1).Items, FOF_CREATEPROGRESSDLG

wScript.Sleep 1000

wscript.echo "Done!"

*****************


After the folder/subfolder/files have been zipped and moved, I'd like to "clean" the source directory.   That is, I'd like to delete all files from the root directory and any subfolder/sub-subfolders.    I do NOT, however, want to delete the folders/subfolders.

How can the VBS be modified to accomplish this task?

Thanks,
EEH
SOLUTION
Avatar of chaau
chaau
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ExpExchHelp

ASKER

chaau:

Almost there!   Great!

I had to remove "Dim" on line 30.   I then executed and moved the zip file.

When I checked the source directory, the subfolders were empty; however, any files on the directory's root level were still there.

How can the code be tweaked to include those that that directly on the folder level (i.e., same level as the subfolders)?

EEH
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
MOST PERFECT SOLUTION!!!   Thank you, chaau.  ;)

EEH
I have a follow-on question on the posting above (https://www.experts-exchange.com/questions/28294665/Batch-file.html?anchorAnswerId=39649505#a39649505)

How can add a date-time-stamp to the output file "MPA.zip"?

So, if this batch is processed on, e.g., March 20 @ 3:15 pm, I would like the filename to be as follows:   "MPA_2014_03_15-1515.zip".     If the date format will be different, that's fine as well.   Goal is to be able to add date and time to the file.

Is that doable?   If yes, how should the code be modified to accommodate this task?

EEH
I can somebody has already provided you with a solution in another question. I think their solution is great. I hope it will help you in your project
chaau:

Thanks... I've tried bp's solution.   At this time though, it doesn't execute.  

I'm sure the error is mine.   I'd welcome if you could chime in (since it's your original code).

Thanks,
EEH