Advertisement:

Author Topic: Cannot get sub folder information  (Read 1020 times)

Offline Robdogg3058

  • Newbie
  • *
  • Posts: 1
Cannot get sub folder information
« on: April 30, 2012, 04:54:48 AM »
Hi


I am kind of new to scripting and have nearly got my script to work but 1 last bit isn't working.

The aim of my script is to scan a folder and give me a list of requested fields for all files and sub folder files in a selected folder and out put it to a text file.  At the moment it gives me all the information for the files in the root directory but not for any subfolders.


How can I edit my script to get this to work?

Thanks

Rob


Here is my script

Dim fso, folder, subFlds, files, OutputFile
Dim strPath

' Create a FileSystemObject 
Set fso = CreateObject("Scripting.FileSystemObject")

' Define folder we want to list files from
strPath = "Rob"

Set folder = fso.GetFolder(strPath)
Set subFlds = folder.SubFolders
Set files = folder.Files

' Create text file to output test data
Set OutputFile = fso.CreateTextFile("ScriptOutput.txt", True)

' Loop through each file 
For each item In files

  ' Output file properties to a text file
OutputFile.WriteLine("Name= ")
  OutputFile.WriteLine(item.Name)
OutputFile.WriteLine("")
OutputFile.WriteLine("DateCreated= ")
  OutputFile.WriteLine(item.DateCreated)
OutputFile.WriteLine("")
OutputFile.WriteLine("DateLastAccessed= ")
  OutputFile.WriteLine(item.DateLastAccessed)
OutputFile.WriteLine("")
OutputFile.WriteLine("DateLastModified= ")
  OutputFile.WriteLine(item.DateLastModified)
OutputFile.WriteLine("")
OutputFile.WriteLine("Drive= ")
  OutputFile.WriteLine(item.Drive)
OutputFile.WriteLine("")
OutputFile.WriteLine("ParentFolder= ")
  OutputFile.WriteLine(item.ParentFolder)
OutputFile.WriteLine("")
OutputFile.WriteLine("Path= ")
  OutputFile.WriteLine(item.Path)
OutputFile.WriteLine("")
OutputFile.WriteLine("Size= ")
  OutputFile.WriteLine(item.Size)
OutputFile.WriteLine("")
OutputFile.WriteLine("Type= ")
  OutputFile.WriteLine(item.Type)   
  OutputFile.WriteLine("------------------------------------------------")
OutputFile.WriteLine("")
 
Next

' Close text file
OutputFile.Close



Offline MrPhil

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,652
Re: Cannot get sub folder information
« Reply #1 on: April 30, 2012, 11:42:25 AM »
What language is this, VB? Anyway, the usual way to do this in other languages is to explicitly open each directory you encounter, and recursively process it. Normally, simply reading one directory won't follow its subdirectories down the tree (unless VB has something like that built in).
Please do not PM me with support questions, unless I ask you to. Unsolicited PMs for support will be ignored. It's best to have questions and answers in public, so others can research a problem and learn about it without having to ask the question yet again. Thank you!
FAQs | SMF 1.1 fixes | Project ideas
-= From the ashes shall rise a sooty tern =-