This script will customizes each of the sub folders listed under the specified "sStartFolder" with a descriptive icon.
Download IconAnyFolder (vbs file)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- sStartFolder = "D:\Text Editors"
-
- iDTfiles = 0
- CRLF = Chr (13) + Chr (10)
- sTitle = "Icon Any Folder"
-
- Welcome()
-
- Set oFSO = CreateObject ("Scripting.FileSystemObject")
- Set oWSH = CreateObject ("WScript.Shell")
-
- Start(sStartFolder)
- sMsg = "Script Is complete. " & iDTfiles & " folders have been customized."
- MsgBox sMsg, vbInformation , sTitle
-
- Sub Start(sPath)
-
- Set oFolder = oFSO.GetFolder(sPath)
-
- SetIcon(oFolder)
-
- End Sub
-
- Function SetIcon(oFolder)
-
- SetIcon = ""
- bFoundIcon = False
- For Each File In oFolder.Files
- If LCase (Right (File.Name,3)) = "ico" Then
- If GoodIcon(File.Name, oFolder.Name) Then
- bFoundIcon = True
- Exit For
- End If
- End If
- Next
- If bFoundIcon = False Then
- For Each File In oFolder.Files
- If LCase (Right (File.Name,3)) = "exe" Then
- If GoodIcon(File.Name, oFolder.Name) Then
- bFoundIcon = True
- Exit For
- End If
- End If
- Next
- End If
-
-
-
-
-
-
-
-
-
-
- For Each Folder In oFolder.SubFolders
- SubIcon = SetIcon(Folder)
- Next
- If bFoundIcon = True Then
- SetIcon = oFolder.Path & "\" & File.Name & "," & 0
- WriteDTfile oFolder, SetIcon
- Else
- SetIcon = SubIcon & "," & 0
- End If
-
- End Function
-
-
- Function GoodIcon(FileName, FolderName)
- GoodIcon = True
-
-
- If Not InStr (LCase (FileName), "unins") = 0 Then GoodIcon = False
- If Not InStr (LCase (FileName), "setup") = 0 Then GoodIcon = False
- End Function
-
- Sub WriteDTfile(Folder, sIconFile)
-
- aIcon = Split (sIconFile, ",")
- If aIcon(0) = "" Then Exit Sub
- If Not IsNumeric (aIcon(1)) Then aIcon(1) = 0
- sDTfile = Folder.path & "\Desktop.ini"
- WriteKey ".ShellClassInfo", "IconFile", SysEnvRe(aIcon(0)), sDTfile
- WriteKey ".ShellClassInfo", "IconIndex", aIcon(1), sDTfile
-
- If (Folder.Attributes And 1) <> 1 Then Folder.Attributes = Folder.Attributes + 1
-
- iDTfiles = iDTfiles + 1
- End Sub
-
- Sub WriteKey(Section, KeyName, Value, FileName)
- On Error Resume Next
-
- If oFSO.FileExists(FileName) Then
- Set fDT = oFSO.GetFile(FileName)
-
- fDT.Attributes = 0
- INIContents = ""
- Set TextStream = fDT.OpenAsTextStream(1)
- Do While Not TextStream.AtEndOfStream
- INIContents = INIContents & TextStream.ReadLine & CRLF
- Loop
- TextStream.Close
-
- If Len (INIContents) > 3 Then
- INIContents = Left (INIContents, Len (INIContents) - 2)
- End If
- Else
- INIContents = ""
- End If
-
- PosSection = InStr (1, INIContents, "[" & Section & "]")
- If PosSection > 0 Then
-
- PosEndSection = InStr (PosSection, INIContents, CRLF & "[")
-
- If PosEndSection = 0 Then PosEndSection = Len (INIContents) + 1
-
- OldsContents = Mid (INIContents, PosSection, PosEndSection - PosSection)
- OldsContents = Split (OldsContents, CRLF)
-
- sKeyName = LCase (KeyName & "=")
-
- For Each Line In OldsContents
- If LCase (Left (Line, Len (sKeyName))) = sKeyName Then
- Line = KeyName & "=" & Value
- Found = True
- End If
- NewContents = NewContents & Line & CRLF
- Next
- If IsEmpty (Found) Then
-
- NewContents = NewContents & KeyName & "=" & Value
- Else
-
- NewContents = Left (NewContents, Len (NewContents) - 2)
- End If
-
- NewContents = Left (INIContents, PosSection - 1) & NewContents
- NewContents = NewContents & Mid (INIContents, PosEndSection)
- Else
-
- If Right (INIContents, 2) <> CRLF And Len (INIContents) > 0 Then
- INIContents = INIContents & CRLF
- End If
- NewContents = INIContents & "[" & Section & "]" & CRLF & KeyName & "=" & Value
- End If
- Set TextStream = oFSO.CreateTextFile(FileName, True )
- TextStream.Write NewContents
- TextStream.Close
- Set fDT = oFSO.GetFile(FileName)
-
- fDT.Attributes = fDT.Attributes + 3
- End Sub
-
-
-
- Function SysEnvRe(path)
- SysEnvRe = path
- vars = Array ("APPDATA", "ALLUSERSPROFILE", "USERPROFILE", "ProgramFiles", "SystemRoot")
- Set SysEnv = oWSH.Environment("PROCESS")
-
- For Each var In vars
- SysEnvRe = Replace (SysEnvRe, SysEnv(var),"%" & var & "%")
- Next
- End Function
-
- Sub Welcome()
- sMessage = "This script will customizes Each of the folders" & _
- " listed In " & sStartFolder & " With descriptive icons."
- iAns = MsgBox (sMessage, vbOKCancel + vbInformation , sTitle)
- If iAns = vbCancel Then
- WScript.Quit
- End If
- End Sub
Download IconAnyFolder (vbs file)