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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error in script

Status
Not open for further replies.

murphyg

Technical User
Feb 5, 2004
23
GB
Hello all,

Could somone help me with this search script please, it fails on the fuction, but haven't a clue why any help would be appriciated

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Option Explicit

Dim ObjFSO
Dim ObjStartDrive
Dim ObjFolder
Dim Folder
Dim ObjFile

Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set ObjStartDrive = ObjFSO.GetFolder("c:\")

For Each ObjFolder In ObjStartDrive.SubFolders
FindFiles(Folder)

Function FindFiles(Folder)

Set Folder = ObjFSO.GetFolder(Folder)
For Each ObjFile In Folder.Files
If InStr(1, ObjFile.Name, ".zip", 1) Then
WScript.Echo ObjFile.Path
Wscript.Echo ObjFile.DateCreated
Else
End If
Next

If Folder.SubFolders.Count > 0 Then
For Each Folder In Folder.SubFolders
FindFiles(Folder.Path)
Next
End If

End Function
 
sorry forgot to mention the error
(15, 1) Microsoft VBScript compilation error: Syntax error
 
>it fails on the fuction, but haven't a clue why...
You have practically mistakes in concept every three lines.
[1] Missing next for for-loop.
[2] Mistaken object and default string property of folder.
[3] Wrong method of calling function without return.
[4] Repeated folder variable for different thing.
[5] Liberal use/abuse of global scope.

Do a search for a better examples. To salvage your lines, this is how it is done and you may see more clear your mistakes or better practice.
[tt]
Option Explicit

Dim ObjFSO
Dim ObjStartDrive
Dim ObjFolder
[red]'[/red]Dim Folder
[red]'[/red]Dim ObjFile

Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set ObjStartDrive = ObjFSO.GetFolder("c:\")

For Each ObjFolder In ObjStartDrive.SubFolders
[red]call[/red] FindFiles([red]obj[/red]Folder[red].path[/red])
[red]Next[/red]

Function FindFiles([blue]s[/blue]Folder)

[blue]dim Folder,objFolder,objFile[/blue]
Set Folder = ObjFSO.GetFolder([red]s[/red]Folder)
For Each ObjFile In Folder.Files
If InStr(1, ObjFile.Name, ".zip", 1) Then
WScript.Echo ObjFile.Path
Wscript.Echo ObjFile.DateCreated
Else
End If
Next

If Folder.SubFolders.Count > 0 Then
For Each [blue]obj[/blue]Folder In Folder.SubFolders
[red]call[/red] FindFiles([blue]obj[/blue]Folder.Path)
Next
End If

End Function
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top