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)
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)