Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Log and zip

Status
Not open for further replies.

scottohum

IS-IT--Management
Jul 5, 2011
14
0
0
GB
i am trying to make this script create a log of all files on C:\ and then zip the file. i can get the two functions to work individualy but when i try to put them into one VBS i get error on line32 char1 saying expected statement. Im sure its just something simple i have missed. Here's my script....:

Option Explicit
Const FOR_READING = 1
Const FOR_WRITING = 2
Const FOR_APPENDING = 8

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim Folder, FolderItem, f, LogFile
Dim strDirectory : strDirectory = "C:\"
Set Folder = objFSO.GetFolder(strDirectory)
LogFile = "C:\FilesList.txt"
Set f = objFSO.CreateTextFile(LogFile, 2)

getDirList Folder, f
f.Close
Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "notepad " & LogFile

Sub getDirList(pCurrentDir, f)
On Error Resume Next
Dim aItem, bItem
For Each aItem In pCurrentDir.Files
If Err.Number = 424 Or Err.Number = 70 Then
Err.Clear
Else
f.Writeline(aItem)
End If
Next

For Each bItem In pCurrentDir.SubFolders
getDirList bItem, f
Next
End Sub 'getDirList()

Option Explicit
Const FOF_SIMPLEPROGRESS = 256
Dim MySource, MyTarget, MyHex, MyBinary, i
Dim oShell, oCTF
Dim oFileSys
dim winShell
MySource = "C:\FilesList.txt"
MyTarget = "C:\FilesList.zip"
MyHex = Array(80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
For i = 0 To UBound(MyHex)
MyBinary = MyBinary & Chr(MyHex(i))
Next
Set oShell = CreateObject("WScript.Shell")
Set oFileSys = CreateObject("Scripting.FileSystemObject")
'Create the basis of a zip file.
Set oCTF = oFileSys.CreateTextFile(MyTarget, True)
oCTF.Write MyBinary
oCTF.Close
Set oCTF = Nothing
'Add File to zip
set winShell = createObject("shell.application")
winShell.namespace(MyTarget).CopyHere MySource
wScript.Sleep(5000)
 
Get rid of the second Option Explicit instruction.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top