SimonJohnG
asked on
VB invalid procedure call or argument
The code below was created to perform a directory listing on a local folder then output it comma delimited to a file on the network. It all works fine unless the listing comes across an invalid file name. In this case error 800A0005 (Invalid procedure call or argument is thrown up on line 14 char 2. Is there some method to ignore such a file or change how the data is output to allow its inclusion. If the only method is to output to an un-delimited text file that would be ok too. I have limited experience so if possible to resolve please modify. All I really need is an out to a file with the directory contents, no bells or whistles if that's what it takes.
Regards
S
Regards
S
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim WshNetwork
Set WshNetwork = CreateObject("WScript.Network")
ComputerName = WshNetwork.ComputerName
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders ("Desktop")
strRootFolder = strDesktop & "\FOLDER"
strOutputFile = "\\serverdc02\office\SoftHardAudit\ConfDir\LaptopConfDirListings" & "\" & computername & "DirListing.csv"
strResults = ""
EnumerateFolder(strRootFolder)
Set objOutput = objFSO.CreateTextFile(strOutputFile, True)
objOutput.Write strResults
objOutput.Close
Sub EnumerateFolder(objFolder)
For Each objFile In objFSO.GetFolder(objFolder).Files
If strResults = "" Then
strResults = """" & Replace(objFile.Path, "\", """,""") & """"
Else
strResults = strResults & VbCrLf & """" & Replace(objFile.Path, "\", """,""") & """"
End If
Next
For Each objSubFolder In objFSO.GetFolder(objFolder).SubFolders
EnumerateFolder objSubFolder
Next
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Should be in the line before you get the error. Should be line 13, right?
ASKER
Thank you but is there any method so the directory listing can continue? Say all files except those that cannot be successfully listed?
Then I think you need to check for those exceptions in your EnumerateFolder procedure, inside the For Each objFile loop.
ASKER
If only I knew how to do that which I don't.
Thank you for the suggestion
Thank you for the suggestion
ASKER
Just noticed that the files are not invalid file names, they are filenames with Japanese characters, anyway of getting around this?
Regards
S
Regards
S
Not really. Sorry.
Just noticed that the files are not invalid file names, they are filenames with Japanese characters, anyway of getting around this?
Since the OS doesn't allow naming a file with certain reserved characters (such as \/:*?""<>|) that's probably why you're getting that error. So what you have to do is simply remove any of these chars from the fileaname before attempting to create the file.
Public Function removeCraps(ByVal sMyString, _
Optional ByVal CRAPS = "\/:*?""<>|", _
Optional ByVal sReplaceWith)
Dim ii
For ii = 1 To Len(CRAPS)
sMyString = Replace(sMyString, Mid$(CRAPS, ii, 1), sReplaceWith)
Next
removeCraps = sMyString
End Function
Now, on line 13, simply:
strOutputFile = RemoveCraps(strOutputFile)
ASKER
Where would I place this?
Regards
S