Announcement

Collapse
No announcement yet.

Getting a list of files from Host Server

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting a list of files from Host Server

    How do I use the FileSystem Object in VBS to list files in a folder if I don't know the file structure of my host server?

    I'm trying to have random images appear on a web page and the images are located in a directory called 'images'

    Thanks;
    Last edited by donstephens; January 7th, 2010, 03:39 PM.
    Don

  • #2
    Bump...
    Don

    Comment


    • #3
      Attached is a .vbs that drills down to all subfolders and counts the lines in each file of the subfolder. You can use it as an example.

      Code:
      Dim TotalSize(12)
      Dim TotalCount(12)
      Dim iLevel
      Dim Indent
      Dim Dots
      Dim Spaces
      Dim Title
      Dim fso
      Dim tso
      Dim here
      
      set fso = CreateObject("Scripting.FileSystemObject")
      here = WScript.ScriptFullName
      if fso.FileExists(replace(here,".vbs",".txt")) then
          fso.DeleteFile(replace(here,".vbs",".txt"))
      end if
      set tso = fso.CreateTextFile(replace(here,".vbs",".txt"))
      
      
      Indent = 1
      iLevel = 0
      Dots =  " ...|....|....|....|....|....|....|....|....|....|....|....|....|"
      Spaces= "                                                                 "
      Title = "Folder / Filename                                                 Size     Line Count"
      
      for i = 0 to 12
          TotalSize(i) = 0
          TotalCount(i) = 0
      next
      
      
      tso.Writeline Title
      DrillDown fso.GetFolder(left(here,instrRev(here,"\")-1))
      
      set tso = nothing
      set fso = nothing
      
      sub DrillDown(oFolder)
          tso.Writeline left(Dots,Indent) & oFolder.Name 
          Indent = Indent + 2
          iLevel = iLevel + 1
          for each oFile in oFolder.Files
              tso.Writeline Left(left(Dots,Indent) & oFile.Name & spaces,55) &  Right(spaces & FormatNumber(oFile.size,0),15) & Right(spaces & FormatNumber(LineCount(oFile),0),15)
              for i = 0 to iLevel
      	    Totalsize(i) = TotalSize(i) + oFile.size
      	Next
          next
          tso.Writeline Left(left(Dots,Indent) & spaces,55) &  Right(spaces & "------" ,15) & Right(spaces & "------",15)
          tso.Writeline Left(left(Dots,Indent) & "Total" & spaces,55) &  Right(spaces & FormatNumber(TotalSize(iLevel),0),15) & Right(spaces & FormatNumber(TotalCount(iLevel),0),15)
          tso.Writeline
      
          for each oSubFolder in oFolder.subFolders
              DrillDown oSubFolder
          next
      
          Indent = Indent - 2
          tso.Writeline Left(left(Dots,Indent) & spaces,55) &  Right(spaces & "------" ,15) & Right(spaces & "------",15)
          tso.Writeline Left(left(Dots,Indent) & "Total" & spaces,55) &  Right(spaces & FormatNumber(TotalSize(iLevel),0),15) & Right(spaces & FormatNumber(TotalCount(iLevel),0),15)
          tso.Writeline
          TotalSize(iLevel) = 0
          TotalCount(iLevel) = 0
          iLevel = iLevel - 1
      end sub
      
      Function LineCount(oFile)
          Dim tso, iCount
          set tso = fso.OpenTextFile(oFile.path)
          iCount = 0
          Do Until tso.AtEndOfStream
              s = tso.ReadLine
              if trim(s) <> "" then
                  iCount = iCount + 1
              End if
          Loop
          set tso = Nothing
          LineCount = iCount
          for i = 0 to iLevel
              TotalCount(i) = TotalCount(i) + iCount
          next
      end Function

      Comment


      • #4
        Thanks!
        Don

        Comment

        Working...
        X