Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Unzip "unknown" file script  (Read 2341 times)

0 Members and 1 Guest are viewing this topic.

piezomot

    Topic Starter


    Newbie

    Unzip "unknown" file script
    « on: October 27, 2008, 12:09:10 PM »
    Hi, I am new to VBS scripts. Here is my problem. I have a zip file generated by my PC drive A:\ and each time I have a different file name name generated for example line SDD+6+20+6536+1+PD+20081027+105138.zip

    This is what i need to do. I need to have VBS script which would unzip this file into my C:\temp without knowing the file name...

    This is where I am with it:

    Step1- this script would copy the above mentioned file from A:\ to C:\
    Code: [Select]
    Const OverwriteExisting = True
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.CopyFile "A:\*.zip" , "C:\temp" , OverwriteExisting

    Step2- grab the name of the file in C:\temp
    Code: [Select]
    'Option Explicit
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Dim objFSO, objFldr, objSFldr, objFl, objStream, sFile, sPath, sExtension
    '// Create the FileSystemObject
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    '// The file you want the dir printed to...
    sFile = "C:\temp\filename.txt"
    '// The folder you want a dir of...
    sPath = "C:\temp"
    Set objStream = objFSO.OpenTextFile(sFile, ForAppending, True)
    '// Get the folder
    Set objFldr = objFSO.GetFolder(sPath)
    For Each objSFldr in objFldr.SubFolders
    For Each objFl in objFldr.Files
    sExtension = "." & StripExtension(objFl.name)
    objStream.WriteLine Replace(StripFilename(objFl.Name), sExtension, "")
    Next
    Next
    objStream.Close
    Set objFSO = Nothing
    Set objStream = Nothing
    Set objFldr = Nothing
    Set objFl = Nothing

    Function StripFilename(strFile)
      dim sTemp
      sTemp = Split(strFile, "\")
      StripFilename = sTemp(UBound(sTemp))
    End Function

    Function StripExtension(strFile)
      Dim sTemp
      sTemp = Split(strFile, ".")
      StripExtension = sTemp(UBound(sTemp))
    End Function

    Step3 - unzip the file into C:\temp directory
    Code: [Select]
    strZipFolder = "C:\myfilename.zip"                                       'name of zip file
      outFolder = "C:\temp"                                       'destination folder of unzipped files
     
      Set objShell = CreateObject( "Shell.Application" )
      Set objSource = objShell.NameSpace(strZipFolder).Items()
      Set objTarget = objShell.NameSpace(outFolder)
      intOptions = 256
      objTarget.CopyHere objSource, intOptions

    In step2 the script would dump the filename into the file filename.txt but I want it to substitute that file name with myfalename name so I can unzip that file.

    Can anyone help me?

    Thanks.

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Unzip "unknown" file script
    « Reply #1 on: October 27, 2008, 04:22:30 PM »
    Unless I missed something, you copied all the files from the floppy to temp. Then you create a text file listing the contents of temp. Then you decompress the zips from temp.

    In step 2 you have a handle to the files to unzip (objFl). Try moving the unzip logic from step 3 to step 2. After writing to filename.txt, you can use objFl.Path as the strZipFolder.

    Another solution would be to copy each file from the floppy one at a time and doing the unzipping in step 1 directly off the floppy. The would prevent zip files mixing in with other extensions.

     8)



    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein