# Need some batch file help please



## 0writer (Nov 21, 2011)

Hello,

I am trying to write a batch file to "capture" multiple txt files burried within multiple directories and then zip the files it has "captured" and email it.

To explain a bit better, I have a folders called Logs and within this are folders which a named in YYYYMMDD format. Within each of these folders is a text file called SMSLog_YYYYMMDD.txt

I'm trying to create a batch file that I can schedule to run at the end of each month that will grab all of the *.txt files for that month, zip them and email them to me. 

We have a local email server that we can use to send the email which is smtp.

I'd really appriciate any help you can offer.

Thanks in advance


----------



## Squashman (Apr 4, 2003)

So lets see the code you have started so far.


----------



## 0writer (Nov 21, 2011)

Well, all I have so far are snipets of code from browsing but because I don't have the knowledge to chop and change them, that's where I'm getting stuck.

Here is some code I've found for zipping (but it will only zip a specific file)


```
set FILETOZIP=c:\ue_english.txt       set TEMPDIR=C:\temp738     rmdir %TEMPDIR%     mkdir %TEMPDIR%     copy %FILETOZIP% %TEMPDIR%      echo Set objArgs = WScript.Arguments > _zipIt.vbs     echo InputFolder = objArgs(0) >> _zipIt.vbs     echo ZipFile = objArgs(1) >> _zipIt.vbs     echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> _zipIt.vbs     echo Set objShell = CreateObject("Shell.Application") >> _zipIt.vbs     echo Set source = objShell.NameSpace(InputFolder).Items >> _zipIt.vbs     echo objShell.NameSpace(ZipFile).CopyHere(source) >> _zipIt.vbs     echo wScript.Sleep 2000 >> _zipIt.vbs      CScript  _zipIt.vbs  %TEMPDIR%  C:\someArchive.zip      pause
```
I've got some vbs code to send an email using our internal smtp server and that's working nicely (I use it already for some other stuff).

Thanks,


----------



## Squashman (Apr 4, 2003)

A lot of the code you have already is VB script. Can't help you with that. I don't know much about VBscript.


----------



## centauricw (Jun 26, 2010)

I would go ahead and write the VBScript script file as a standalone .vbs file rather than trying to create it as part of the batch file. This will make debugging the the VBScript much, much easy. Then you can call the VBScript from a batch file, passing in any arguments it needs.


```
cscript //nologo c:\path-to-my-script-folder\myscript.vbs Argument1 "Argument 2 with spaces"
```
I like using cscript (//nologo suppresses the logo banner), but if you're not using anything only supported by cscript, you can use wscript instead.


----------

