none
Need help combining 2 vbs scripts. RRS feed

  • Question

  • Hi Guys,

    Firstly i dont have any scripting background so i am absolutely new to this.

    I work for an Engineering Company that produces a lot of Construction drawings (PDFs & DWGs). These when sent out are generally zipped individually and i find it extremely annoying to have to zip them as it is a painstaking task that chews up a lot of valuable time. In a hope to automate the process, i began looking online for scripts that would help facilitate this. 

    For most parts i was successful. I was able to use a few scripts available online to come up with:

    SET SourceDir=C:\Users\Desktop\New folder\Temp
    SET DestDir=C:\Users\Desktop\New folder\Temp

    CD /D "C:\Program Files\7-Zip"
    FOR /F "TOKENS=*" %%F IN ('DIR /B /A-D "%SourceDir%"') DO (
        7z.exe a "%DestDir%\%%~NF.zip" "%SourceDir%\%%~NXF"
    )
    EXIT

    This was soooo HUGE!. I was able to zip ~1000 files in mere minutes as opposed to the hours it took the doc controller.

    The above code required the user to input the directory.

    Now to take it a step further. I was hoping to create a user interface so that the interface will let the user set the "source" and "destination" directory instead of having to edit the scrip txt file.

    Again i was able to find something online that did exactly this.

    Dim objShell
    Dim strFileName
    Dim strFilePath
    dim strDestinationPath
    Dim objSource
    Dim objDestination
    Dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("Shell.Application")
    Set objSource = objShell.BrowseForFolder(0, "Choose the source directory to zip:", &H4000,17)
    strFileName = objSource.Title
    strFilePath = objSource.self.Path
    Set objDestination = objShell.BrowseForFolder(0, "Choose the destination directory to output:", &H4000,17)
    strDestinationPath = objDestination.self.Path

    Set ts = objFSO.CreateTextFile("C:\Temp\Folder.txt",True)
    ts.Write strFilePath
    ts.Write strDestinationPath
    ts.Close

    Now i am stuck trying to combine these 2 and could use some direction or advise (that will make sense to a first timer).

    Cheers

    Daniel

    Saturday, June 1, 2019 4:08 AM

All replies