0

I am very new to VB Scripting and I am looking to see if there is a way to look at a directory get the file names and then write those file names to a text file. I would think that the Path.GetFileName Method would work, but I can't seem to get it to work. Maybe I am using it the wrong way.

Meister
  • 3
  • 1
  • 3
  • 2
    What about sharing some code? – user1567896 Dec 17 '13 at 20:08
  • 2
    There is no Path object in VBScript. So start yout research here: http://msdn.microsoft.com/en-us/library/6tkce7xa%28v=vs.84%29.aspx – Ekkehard.Horner Dec 17 '13 at 20:09
  • A very tiny effort (like looking in the Related list) yielded [Read and write into a file using VBScript](http://stackoverflow.com/q/1142678/62576) for the "write to file" part, and [Print out files in a directory sorted by FileName](http://stackoverflow.com/questions/18209617/print-out-files-in-a-directory-sorted-by-filename) for the "getting filenames" part. – Ken White Dec 17 '13 at 20:14
  • I dont need to print the documnets out, but thanks Dan was able to get me what I need. Thanks for the input from everyone. what books do you recommend reading for learning VB Scripting? – Meister Dec 17 '13 at 20:41

1 Answers1

2

Here is a simple script that will echo the filenames in the "C:\Windows\" directory.

Set fs = CreateObject("Scripting.FileSystemObject")
'Log file name
Set logFile = fs.OpenTextFile("fileNameLogs.txt", 2, True)
'Directory you want listed
Set folder = fs.GetFolder("c:\windows\")

Set files = folder.Files
  For Each file in files
    wscript.echo file.name
    logFile.writeline(file.name)
  Next
logFile.close
Dan K
  • 409
  • 3
  • 12