Advertisement
Twilypastes

imagelist-generate.vbs

Sep 25th, 2015
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2. ' Author:      Twily                                                 2015
  3. ' Description: Generate a list of images from a specific path to use with
  4. '              the homepage-sidebar.html (this includes subdirectories).
  5. ' Website:     http://twily.info/
  6.  
  7. Dim strPath,strData,tmpList,objFSO,objTS,objShell
  8.  
  9. Set objFSO=CreateObject("Scripting.FileSystemObject")
  10.  
  11. tmpList="C:\imagelist.txt"
  12. strPath=objFSO.GetAbsolutePathName(".")
  13.  
  14. Sub Recurse(objFolder)
  15.     Dim strName,objFile,objSubFolder,objExt
  16.  
  17.     For Each objFile In objFolder.Files
  18.         objExt=LCase(objFSO.GetExtensionName(objFile.Name))
  19.  
  20.         If objExt="jpg" or objExt="jpeg" or objExt="png" Then
  21.             strName=Replace(objFile.Path,strPath,"")
  22.             strName=Replace(strName,"\","/")
  23.             strName=Replace(strName,"%","%25")
  24.  
  25.             'objTS.Write("""" & strName & """,")
  26.            objTS.WriteLine("""" & strName & """,")
  27.         End If
  28.     Next
  29.  
  30.     For Each objSubFolder In objFolder.SubFolders
  31.         Recurse objSubFolder
  32.     Next
  33. End Sub
  34.  
  35. Do
  36.  
  37. strPath=InputBox("Enter path to images: ","Imagelist-generator",strPath)
  38.  
  39. If objFSO.FolderExists(strPath) Then
  40.     Set objTS=objFSO.OpenTextFile(tmpList,2,True)
  41.    
  42.     Recurse objFSO.GetFolder(strPath)
  43.     objTS.Close()
  44.    
  45.     Set objShell=WScript.CreateObject("WScript.Shell")
  46.     objShell.Run "notepad.exe " & tmpList
  47.    
  48.     strPath=Replace(strPath,"\","/")
  49.     strPath=Replace(strPath,"%","%25")
  50.     InputBox "Path to use with imagelist: ","Imagelist-generator","file:///" & strPath
  51.    
  52.     objFSO.DeleteFile tmpList,True
  53.  
  54.     Exit Do
  55. ElseIf Len(strPath) Then
  56.     MsgBox "Error: Invalid path.",vbCritical,"Error"
  57. Else
  58.     Exit Do
  59. End If
  60.  
  61. Loop
  62.  
  63. WScript.Quit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement