1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Need some batch file help please

Discussion in 'DOS/Other' started by 0writer, Nov 21, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. 0writer

    0writer Thread Starter

    Joined:
    Nov 21, 2011
    Messages:
    2
    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
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    So lets see the code you have started so far.
     
  3. 0writer

    0writer Thread Starter

    Joined:
    Nov 21, 2011
    Messages:
    2
    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)


    Code:
    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,
     
  4. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    A lot of the code you have already is VB script. Can't help you with that. I don't know much about VBscript.
     
  5. centauricw

    centauricw

    Joined:
    Jun 26, 2010
    Messages:
    444
    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.

    Code:
    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.
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1027815