janthonyn
asked on
VB Script to echo a list of file names to a text file is not working
VB Script to echo a list of file names to a text file is not working. Running it results in a VBScript runtime error (screen shot attached). I need help making this work.
Here is my code:
cscript FileList.vbs > "\\Domain-01.com\DFS$\care -one\group s\CORPORAT E\Regional Accounting\Monthly Reports\Region Accounting\2014\03 March 2014\NJ\AP\FileList.txt"
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
objStartFolder = "\\Domain-01.com\DFS$\care -one\group s\CORPORAT E\Regional Accounting\Monthly Reports\Region Accounting\2014\03 March 2014\NJ\AP"
Set objFolder = objFSO.GetFolder(objStartF older)
Set colFiles = objFolder.Files
Set objFile = objFSO.CreateTextFile(outF ile,True)
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
VBS-error.png
Here is my code:
cscript FileList.vbs > "\\Domain-01.com\DFS$\care
Set objFSO = CreateObject("Scripting.Fi
objStartFolder = "\\Domain-01.com\DFS$\care
Set objFolder = objFSO.GetFolder(objStartF
Set colFiles = objFolder.Files
Set objFile = objFSO.CreateTextFile(outF
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
VBS-error.png
ASKER
sirbounty,
Thanks, but that didn't work. I ran the script and it returned another error for Line 11 Char 1. The error reads: Object doesn't support this property or method:'objFile.WriteLine' Code: 800A01B6 MSVBS runtime error
Any idea what could be substituted for the code in Line 11?
Thanks, but that didn't work. I ran the script and it returned another error for Line 11 Char 1. The error reads: Object doesn't support this property or method:'objFile.WriteLine'
Any idea what could be substituted for the code in Line 11?
I think it's the duplicate usage of objFile....
Set objFile = objFSO.CreateTextFile(outF ile,True)
For Each oFile in colFiles '<<<change this objFile to oFile
Set objFile = objFSO.CreateTextFile(outF
For Each oFile in colFiles '<<<change this objFile to oFile
ASKER
I made the change and got the same error. My code became the following:
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
outfile="filelist.txt"
objStartFolder = "\\Domain-01.com\DFS$\care -one\group s\CORPORAT E\Regional Accounting\Monthly Reports\Region Accounting\2014\03 March 2014\NJ\AP"
Set objFolder = objFSO.GetFolder(objStartF older)
Set colFiles = objFolder.Files
Set objFile = objFSO.CreateTextFile(outF ile,True)
For Each oFile in colFiles
objFile.WriteLine objFile.Name
Next
VBS-Error.png
Set objFSO = CreateObject("Scripting.Fi
outfile="filelist.txt"
objStartFolder = "\\Domain-01.com\DFS$\care
Set objFolder = objFSO.GetFolder(objStartF
Set colFiles = objFolder.Files
Set objFile = objFSO.CreateTextFile(outF
For Each oFile in colFiles
objFile.WriteLine objFile.Name
Next
VBS-Error.png
Same situation, and my lack of pointing it out.
Your code is still referencing the wrong element, objFile.Name should be oFile.Name:
Your code is still referencing the wrong element, objFile.Name should be oFile.Name:
Set objFile = objFSO.CreateTextFile(outFile,True)
For Each oFile in colFiles
objFile.WriteLine oFile.Name
Next
ASKER
This is not working. I'm still getting an error. <<Object required: 'objFile' Code: 800A01AB, runtime error.
I'm testing it on my local drive now, outside of the workplace network. I've attached the code.
FileList.vbs
I'm testing it on my local drive now, outside of the workplace network. I've attached the code.
FileList.vbs
ASKER
Maybe this is better done with a batch file?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sirbounty
You have restored my faith in experts-exchange. Thank you very much!
You have restored my faith in experts-exchange. Thank you very much!
I know it can be frustrating, but it's a back-and-forth exchange. Were we seated together at a PC, this could have been sorted in about 5 minutes. But since I can't see exactly what's happening on your end, it takes a bit longer.
So glad it's sorted out now though.
Thanks for the grade! :^)
So glad it's sorted out now though.
Thanks for the grade! :^)
Open in new window