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:\
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
'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
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.