How to Use File: Open

Hello,

I am using a .csv file, and my confusion stems from the difference between File Name and File handle in the File: Open function. Under File name, I have a variable equal to the file path of the file and the name of the file, which I traced directly after the File: Open command and saw that the file path was correct (and was even able to copy/paste the file path from the Log File into file explorer to open the file.)

However, I don’t know if I’m defining the File handle correctly. When I traced that after the File: Open function, the file path had an extra \ so instead of ending in \barcode.csv like it does for the File name it ends in \\barcode.csv so it is invalid.

The method then aborts saying that when I go to use File: Read with the File handle I define in File: Open, there is a type mismatch.

Thank you in advance!

Hi, can you show your method?

1 Like

This image as well for additional context

FileTroubleshooting

What’s in column 1 & 3?

Type mismatch indicates it is getting something that’s not correct (e.g. a string is received when an integer is expected). Can you just not read those columns?

Also note that the read file command only reads a single line of the file. If that wasn’t clear. You’ll need to put it into a loop to read multiple lines from a file.

edit: Your file:open step seems to be working fine? The HSL trace code is firing after it’s opened (unless I’m misreading). The error from the trace indicates the problem is on line 1404 which would be the file read step.
.

1 Like

That was the answer, thank you! It was simply that I accidentally had column 3 not set to String.

Yes, I saw that the error was at line 1404 but thought that maybe the File Handle was being incorrectly defined and that is why when the File: Read step was run the file could not be read since it seemed there was an extra towards the end of the File Handle.

Of course! Glad it was a simple fix. Definitely have spent some time troubleshooting weird file path stuff.

It can get pretty confusing with the escape characters (e.g. \), especially if you’re pulling in a path from the browse functionality of the dialogue windows.

Specifying the file path in an assignment needs the escape characters to get the backslashes in whereas pulling the path from a dialog box won’t require it.


Trace file shows the processing of the \ in the test_file variable:
image

Wanted to share since if you try to concatenate a folder onto what users are browsing to (e.g. C:\files → C:\files\lot\file.csv), you’ll have to include the string as “\\lot\\” to build the path appropriately.

edit: I bet there might be a path library or function that makes this simpler though.

2 Likes