Returning a filename from within a For Each statement...

8 posts in this topic

For some reason, I can't get this to work. Basically, I am building in error checking prior to running other functions in an HTA app. I have managed to overcome all odds and have automated an extremely arduous process (processing EDI), but I would also like to error check each EDI file for specific errors. If an error is detected, I want it to tell me which file has the error(s) and how many there are.

The first part of the script runs just fine. It tells me how many EDI files I have in a specific directory. When it gets to the error checking, though, it doesn't work. From all the examples I have seen...it should. I keep getting an error that states: "Object required: '[string: MYFILENAME.EDI"]'

3:\Set objFile = objFileSys.OpenTextFile(objFile) where are the 1, 2, 8

Set objFile = objFileSys.OpenTextFile(objFile,1) would open file for reading

These are used after the error checking is completed by a concatenation script.

4:\ Suggest that you run your script second loop to see what files are being process before checking

for errors.

Example

For Each objFile In objFolder.Files If LCase((objFileSys.GetExtensionName(objFile))) = LCase(EXT) Then wscript.echo ObjFile.Path End If Next

Why would I need a second loop? All of the examples I have seen should allow for the script to report which file is currently being worked on, but it simply isn't working for me. Ideally, I would combine both sections of the script and have it count and error check with the same loop. I'll get to that after the entire script is finished. Keeping them separated allows me to error check the script more easily.

The first part of the script runs just fine. It tells me how many EDI files I have in a specific directory. When it gets to the error checking, though, it doesn't work. From all the examples I have seen...it should. I keep getting an error that states: "Object required: '[string: MYFILENAME.EDI"]'

This is why I said to rewrite your second loop to just show what files are being process, but it your script so it must work.

The first part of the script runs just fine. It tells me how many EDI files I have in a specific directory. When it gets to the error checking, though, it doesn't work. From all the examples I have seen...it should. I keep getting an error that states: "Object required: '[string: MYFILENAME.EDI"]'

This is why I said to rewrite your second loop to just show what files are being process, but it your script so it must work.

OK - I tried it your way, but I still get an error: "Object doesn't support this property or method: 'Path'"