Getting file does not exist when it does

I have a list box that contains a list of text files that exists on the local machine. I plan on doing bulk processing of these files, but I am having an issue getting them assigned properly as a folderitem so I can load in the textfile.

If I use the code below it, to assign the file to be loaded from a listbox cell containg the file information.

The listbox cell(0,0) string contains the complete legal file system path and filename, so I just want the folder item to be what the string is. What am I missing?

Using break to debug, I see that fname is the exact path to the file.

dim t as TextInputStream
dim f as FolderItem
dim i as Integer
dim fname as string


fname = listbox1.Cell(0,0)
f = GetFolderItem(fname)
//break
if f.exists then 
  
  t = TextInputStream.Open(f)
  articletext.Text = t.readall
  
  if T<>nil then 
    T.Close 
  else 
    msgBox "Sorry, couldn't open that file." 
  end if 
  
else
  
  msgBox "Error, file does not exist." 
  
end if 

You might be having some issues because you’re mucking about with file paths.

In your specific case, it’s actually easier to store the FolderItem as the RowTag in the ListBox. You can then pull out the FolderItem and use it directly without having to reconstruct the FolderItem. A general rule of thumb is to avoid messing with FolderItems and paths as much as you can, unless you absolutely have to.

I made you a little example project to learn from: folder_reader.xojo_binary_project

[quote=342837:@Tim Parnell]You might be having some issues because you’re mucking about with file paths.

In your specific case, it’s actually easier to store the FolderItem as the RowTag in the ListBox. You can then pull out the FolderItem and use it directly without having to reconstruct the FolderItem. A general rule of thumb is to avoid messing with FolderItems and paths as much as you can, unless you absolutely have to.

I made you a little example project to learn from: folder_reader.xojo_binary_project[/quote]
Wow Tim impressive, yeah it must be my method of using paths. I’ll study how you are doing it. Thanks for the help

@Tim Parnell

It seems it’s more of a string type versus folderitem issue. I could not add the folder item type as a row /cell item, but yet it works as a rowtag such as your example.

RowTag and CellTags are invisible items that are attached to the row or cell. The Cell value is the text that is displayed.
You can mix and match all three to make ListBox pretty easy to work with, just be careful on larger data sets.

In this example, I used the Cell value to display the text files’ Name in the ListBox for the user, and stored the FolderItem as a RowTag for the code to access.

f = GetFolderItem(fname) //<<< 

note that IF Fname is a complete NATIVE PATH you SHOULD pass the second parameter to getfolderitem to tell it what kind of path it is
see http://documentation.xojo.com/index.php/GetFolderItem

this should maybe be

f = GetFolderItem(fname,FolderItem.PathTypeNative) //<<<