Re: List of files w/i a directory

Subject: Re: List of files w/i a directory
From: Geoff Lane <geoff -at- gjctech -dot- co -dot- uk>
To: TECHWR-L <techwr-l -at- lists -dot- techwr-l -dot- com>
Date: Sat, 13 Jun 2009 10:11:42 +0100

Sorry to tag another reply to my own post, but I've been cleaning out
my mail folders and found the following from 2006. If you're
interested, the entire story can be found in the list archives.
However, here's what I wrote back then when I created a VBS utility to
do exactly what I understand the OP wants but in CSV format for import
into a spreadsheet, database, etc. Just copy the section between the
cut-lines to a text file named "listfiles.vbs" and use as detailed
below:

On Wednesday, August 16, 2006, John Posada wrote;

> Geoff...this was almost perfect and I feel guilty even asking...but,
> can you suppress the directory?
---

The final version follows. I've cleaned up the script a bit and added
another command-line parameter. As before, call with:

wscript listfiles.vbs /dir:<dir to walk> /listfile:<dump file>

By default, the script suppresses the path to each file. However, you
can now include the paths by passing the parameter /path:yes. That is:

wscript listfiles.vbs /dir:<dir to walk> /listfile:<dump file> /path:yes

--------------8<-------------------------
Const ROOTFOLDER = "C:\"
Const LISTFILE = "C:\listfile.txt"

Sub ParseFolder(objFolder)
Dim objFile, strPath, strLine
strPath = objFolder.Path
For Each objFile In objFolder.Files
If bPath Then
strLine = strPath & "\"
Else
strLine = ""
End If
strLine = strLine & objFile.Name & Chr(9) & objFile.Size
fTarget.WriteLine strLine
Next

Dim objSubFolder
For Each objSubFolder In objFolder.SubFolders
ParseFolder objSubFolder
Next

End Sub

'-----------------[ MAIN ]---------------------
Dim fso, objSubFolders, objFolder, fTarget
Dim strTarget, strRootFolder, bPath

If WScript.Arguments.Named.Exists("dir") Then
strRootFolder = WScript.Arguments.Named("dir")
Else
strRootFolder = ROOTFOLDER
End If
If WScript.Arguments.Named.Exists("listfile") Then
strTarget = WScript.Arguments.Named("listfile")
Else
strTarget = LISTFILE
End If
If WScript.Arguments.Named.Exists("path") Then
bPath = True
Else
bPath = False
End If

Set fso = CreateObject("Scripting.FileSystemObject")
Set fTarget = fso.OpenTextFile(strTarget, 2, True)
Set objFolder = fso.GetFolder(strRootFolder)
ParseFolder objFolder
fTarget.Close
Set fTarget = Nothing
Set objFolder = Nothing
Set fso = Nothing
----------------8<-----------------------

HTH,

Geoff

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ComponentOne Doc-To-Help 2009 is your all-in-one authoring and publishing
solution. Author in Doc-To-Help's XML-based editor, Microsoft Word or
HTML and publish to the Web, Help systems or printed manuals.
http://www.doctohelp.com

Help & Manual 5: The complete help authoring tool for individual
authors and teams. Professional power, intuitive interface. Write
once, publish to 8 formats. Multi-user authoring and version control! http://www.helpandmanual.com/

---
You are currently subscribed to TECHWR-L as archive -at- web -dot- techwr-l -dot- com -dot-

To unsubscribe send a blank email to
techwr-l-unsubscribe -at- lists -dot- techwr-l -dot- com
or visit http://lists.techwr-l.com/mailman/options/techwr-l/archive%40web.techwr-l.com


To subscribe, send a blank email to techwr-l-join -at- lists -dot- techwr-l -dot- com

Send administrative questions to admin -at- techwr-l -dot- com -dot- Visit
http://www.techwr-l.com/ for more resources and info.

Please move off-topic discussions to the Chat list, at:
http://lists.techwr-l.com/mailman/listinfo/techwr-l-chat


Follow-Ups:

References:
Re: List of files w/i a directory: From: Paul Kent
Re: List of files w/i a directory: From: Geoff Lane

Previous by Author: Re: List of files w/i a directory
Next by Author: Misc: List Down?
Previous by Thread: Re: List of files w/i a directory
Next by Thread: Re: List of files w/i a directory


What this post helpful? Share it with friends and colleagues:


Sponsored Ads