Discussion:
FileSystemObject: Invalid procedure call or argument Error 800A00
(too old to reply)
Marceepoo
2006-11-04 19:22:01 UTC
Permalink
Line 24 generates the following error: Invalid procedure call or argument
Error 800A00005

The script below runs fine if I comment out lines 24-26, but I need to
create the text file that those lines are intended to create.

Does anyone...
1. Know how to fix those lines so that they work? and
2. Know where I can find reading material so that I would know how to do it
right, i.e., what I'm doing wrong?

Thanks in advance for your time and help.

Marceepoo

'Canniablized from Hey_Scripting_Guy.chm
'
'Get a List of All the Files in a Folder and Its Subfolders
'
'
'
sFileList = ""
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "o:\"

Set objFolder = objFSO.GetFolder(objStartFolder)

Set colFiles = objFolder.Files
For Each objFile in colFiles
sFileList = sFileList & objFile.Name & vbCrLf
'Wscript.Echo objFile.Name
Next

ShowSubfolders objFSO.GetFolder(objStartFolder)

WScript.Echo sFileList


'Set objFile = objFSO.OpenTextFile("o:\NewFile.txt", ForWriting)
'objFile.WriteLine sFileList
'objFile.Close


Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
'Wscript.Echo Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
'Wscript.Echo objFile.Name
sFileList = sFileList & objFile.Name & vbCrLf

Next
'Wscript.Echo
ShowSubFolders Subfolder
Next
End Sub
Michael Harris (MVP)
2006-11-04 22:09:09 UTC
Permalink
Post by Marceepoo
Line 24 generates the following error: Invalid procedure call or
argument Error 800A00005
The script below runs fine if I comment out lines 24-26, but I need to
create the text file that those lines are intended to create.
Does anyone...
1. Know how to fix those lines so that they work? and
Const ForWriting = 2
Post by Marceepoo
2. Know where I can find reading material so that I would know how
to do it right, i.e., what I'm doing wrong?
Download details: Windows Script 5.6 Documentation
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
Post by Marceepoo
Thanks in advance for your time and help.
Marceepoo
'Canniablized from Hey_Scripting_Guy.chm
'
'Get a List of All the Files in a Folder and Its Subfolders
'
'
'
sFileList = ""
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "o:\"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
sFileList = sFileList & objFile.Name & vbCrLf
'Wscript.Echo objFile.Name
Next
ShowSubfolders objFSO.GetFolder(objStartFolder)
WScript.Echo sFileList
'Set objFile = objFSO.OpenTextFile("o:\NewFile.txt", ForWriting)
'objFile.WriteLine sFileList
'objFile.Close
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
'Wscript.Echo Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
'Wscript.Echo objFile.Name
sFileList = sFileList & objFile.Name & vbCrLf
Next
'Wscript.Echo
ShowSubFolders Subfolder
Next
End Sub
--
Michael Harris
Microsoft MVP Scripting
Marceepoo
2006-11-04 23:06:01 UTC
Permalink
Thanks Michael. I inserted the line: "Const ForWriting = 2"
just before the line:
Set objFile = objFSO.OpenTextFile("o:\NewFile.txt", ForWriting)
Now, I get the following error message:
"Line 24
"File not found"

Thanks for trying.
1. Any other ideas?
2. Where should I look inside the script56.chm for the explanation? i.e.,
what search terms or what page, or what should I look for?

Thanks again. Your help is much appreciated.

Marceepoo
Post by Michael Harris (MVP)
Post by Marceepoo
Line 24 generates the following error: Invalid procedure call or
argument Error 800A00005
The script below runs fine if I comment out lines 24-26, but I need to
create the text file that those lines are intended to create.
Does anyone...
1. Know how to fix those lines so that they work? and
Const ForWriting = 2
Post by Marceepoo
2. Know where I can find reading material so that I would know how
to do it right, i.e., what I'm doing wrong?
Download details: Windows Script 5.6 Documentation
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
Post by Marceepoo
Thanks in advance for your time and help.
Marceepoo
'Canniablized from Hey_Scripting_Guy.chm
'
'Get a List of All the Files in a Folder and Its Subfolders
'
'
'
sFileList = ""
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "o:\"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
sFileList = sFileList & objFile.Name & vbCrLf
'Wscript.Echo objFile.Name
Next
ShowSubfolders objFSO.GetFolder(objStartFolder)
WScript.Echo sFileList
'Set objFile = objFSO.OpenTextFile("o:\NewFile.txt", ForWriting)
'objFile.WriteLine sFileList
'objFile.Close
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
'Wscript.Echo Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
'Wscript.Echo objFile.Name
sFileList = sFileList & objFile.Name & vbCrLf
Next
'Wscript.Echo
ShowSubFolders Subfolder
Next
End Sub
--
Michael Harris
Microsoft MVP Scripting
Michael Harris (MVP)
2006-11-05 01:56:40 UTC
Permalink
Post by Marceepoo
Thanks Michael. I inserted the line: "Const ForWriting = 2"
Set objFile = objFSO.OpenTextFile("o:\NewFile.txt", ForWriting)
"Line 24
"File not found"
Thanks for trying.
1. Any other ideas?
Set objFile = objFSO.OpenTextFile("o:\NewFile.txt", ForWriting, True)
Post by Marceepoo
2. Where should I look inside the script56.chm for the explanation?
i.e., what search terms or what page, or what should I look for?
Look at the documentation for the OpenTextFile method. I generally just use
the Index tab...
Post by Marceepoo
Thanks again. Your help is much appreciated.
Marceepoo
Post by Michael Harris (MVP)
Post by Marceepoo
Line 24 generates the following error: Invalid procedure call or
argument Error 800A00005
The script below runs fine if I comment out lines 24-26, but I need
to create the text file that those lines are intended to create.
Does anyone...
1. Know how to fix those lines so that they work? and
Const ForWriting = 2
Post by Marceepoo
2. Know where I can find reading material so that I would know how
to do it right, i.e., what I'm doing wrong?
Download details: Windows Script 5.6 Documentation
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
Post by Marceepoo
Thanks in advance for your time and help.
Marceepoo
'Canniablized from Hey_Scripting_Guy.chm
'
'Get a List of All the Files in a Folder and Its Subfolders
'
'
'
sFileList = ""
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "o:\"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
sFileList = sFileList & objFile.Name & vbCrLf
'Wscript.Echo objFile.Name
Next
ShowSubfolders objFSO.GetFolder(objStartFolder)
WScript.Echo sFileList
'Set objFile = objFSO.OpenTextFile("o:\NewFile.txt", ForWriting)
'objFile.WriteLine sFileList
'objFile.Close
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
'Wscript.Echo Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
'Wscript.Echo objFile.Name
sFileList = sFileList & objFile.Name & vbCrLf
Next
'Wscript.Echo
ShowSubFolders Subfolder
Next
End Sub
--
Michael Harris
Microsoft MVP Scripting
--
Michael Harris
Microsoft MVP Scripting
OfficeGuyGoesWild
2006-11-05 22:10:18 UTC
Permalink
You will find it useful to put these constants at the beginning of any
file in which you are manipulating text files with the file system
object:

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Also, the optional trailing argument can be either True, which will
create the specified file if it does not exist, or False, which won't.

ie:

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

' Instantiate the File System Object
Set fso = CreateObject("Scripting.FileSystemObject")
' Open the server list for reading
Set input = fso.OpenTextFile("servers.txt", ForReading)
' Create an output log file for this execution of the script
Set CurrentLog = fso.CreateTextFile("Current.log",ForWriting,True)
' Create an archive output log file for all executions of the script
Set ArchiveLog = fso.OpenTextFile("Archive.log",ForAppending,True)

..Marty
www.TheScriptLibrary.com
Post by Marceepoo
Line 24 generates the following error: Invalid procedure call or argument
Error 800A00005
The script below runs fine if I comment out lines 24-26, but I need to
create the text file that those lines are intended to create.
Does anyone...
1. Know how to fix those lines so that they work? and
2. Know where I can find reading material so that I would know how to do it
right, i.e., what I'm doing wrong?
Thanks in advance for your time and help.
Marceepoo
'Canniablized from Hey_Scripting_Guy.chm
'
'Get a List of All the Files in a Folder and Its Subfolders
'
'
'
sFileList = ""
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "o:\"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
sFileList = sFileList & objFile.Name & vbCrLf
'Wscript.Echo objFile.Name
Next
ShowSubfolders objFSO.GetFolder(objStartFolder)
WScript.Echo sFileList
'Set objFile = objFSO.OpenTextFile("o:\NewFile.txt", ForWriting)
'objFile.WriteLine sFileList
'objFile.Close
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
'Wscript.Echo Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
'Wscript.Echo objFile.Name
sFileList = sFileList & objFile.Name & vbCrLf
Next
'Wscript.Echo
ShowSubFolders Subfolder
Next
End Sub
Loading...