~siggi-bjarnason/siggivbscript/vbscript

« back to all changes in this revision

Viewing changes to ValidateShortcuts.vbs.txt

  • Committer: Siggi Bjarnason
  • Date: 2011-03-20 00:19:01 UTC
  • Revision ID: siggi@bjarnason.us-20110320001901-qjxjozk911rw164t
Favorites validation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Option Explicit
 
2
Dim FileObj, fso, strOutFileName, objFileOut, HTTP, strDeadLinkFolder
 
3
Dim WshShell, strFavorite, strDocuments, subfolder, subfiles, subFlds2, fld2
 
4
 
 
5
set WshShell = WScript.CreateObject("WScript.Shell")
 
6
strFavorite = WshShell.SpecialFolders("Favorites")
 
7
strDocuments = WshShell.SpecialFolders("MyDocuments")
 
8
 
 
9
strOutFileName = "FavoritesValidation.log"
 
10
 
 
11
strDeadLinkFolder = "DeadLinks"
 
12
 
 
13
Set fso = CreateObject("Scripting.FileSystemObject")
 
14
Set objFileOut = fso.createtextfile(strDocuments & "\" & strOutFileName)
 
15
Set HTTP = CreateObject("Microsoft.XMLHTTP")
 
16
 
 
17
FolderContent strFavorite
 
18
 
 
19
Sub FolderContent (strCurrentFolder)
 
20
        Dim folder, files, file, subFlds, fld, strPath, strLine, strLineParts, bFoundURL
 
21
 
 
22
        Set folder = fso.GetFolder(strCurrentFolder)
 
23
        strPath = mid(folder.path, len(strFavorite)+2)
 
24
        if strPath <> "" then strPath = strPath & "\"
 
25
        Set files = folder.Files
 
26
        Set subFlds = folder.SubFolders
 
27
        
 
28
        For Each file in files
 
29
                if file.name <> "desktop.ini" then
 
30
                        bFoundURL = false
 
31
'                       wscript.echo "Opening " & file.path '& "\" & file.name
 
32
                        Set FileObj = fso.opentextfile(file.path)
 
33
'                       writeout strpath & file.name
 
34
                        While not fileobj.atendofstream
 
35
                                strLine = Trim(FileObj.readline)
 
36
                                strLineParts = split (strLine, "=")
 
37
                                If strLineParts(0) = "URL" Then
 
38
'                                       wscript.echo "testing URL " & strLineParts(1)
 
39
                                on error resume next
 
40
                                        HTTP.Open "GET", strLineParts(1), False
 
41
                                        HTTP.Send
 
42
                                        if Err.Number > 0 then
 
43
                                                writeout strpath & file.name & "; " & strLineParts(1) & "; " & Err.Number & Err.Description
 
44
                                        else
 
45
                                                writeout strpath & file.name & "; " & strLineParts(1) & "; " & HTTP.statusText
 
46
                                        end if
 
47
                                on error goto 0
 
48
                                        If HTTP.statusText <> "OK" Then
 
49
'                                               writeout strLineParts(1) & " is not OK, moving to c:\" & strDeadLinkFolder & "\" & file.name
 
50
'                                               file.copy ("c:\" & strDeadLinkFolder & "\" & file.name)
 
51
'                                               file.move ("c:\" & strDeadLinkFolder & "\" & file.name)
 
52
'                                               file.delete (true)
 
53
'                                               fso.movefile file.path, "c:\" & strDeadLinkFolder & "\" & file.name
 
54
                                        End If
 
55
                                        bFoundURL = true
 
56
                                End If 
 
57
                        Wend
 
58
                        if bFoundURL = false Then
 
59
                                writeout "Couldn't find URL in " & file.path & "\" & file.name
 
60
                        End If
 
61
                End if
 
62
        Next
 
63
        For Each fld in subFlds
 
64
                FolderContent fld
 
65
        Next
 
66
End Sub
 
67
 
 
68
Sub writeout (msg)
 
69
        
 
70
        wscript.echo msg
 
71
        objFileOut.writeline msg
 
72
 
 
73
End Sub