When I check for errors Xojo is telling me to change the line that reads:
pName = f.AbsolutePath (to)
pName = f.NativePath
Yet when I do this I get a IOException error and my program crashes! - WHATS GOING ON?
(By the way - Its a routine that lets the user select a CSV file, parses it, then puts the contents in a Listbox)
Heres the code if anybody is interested…
1 X Button called PushButton1 - 1 X Listbox called ListBox1 - 1 X Method called ImportList (parameters - FileName As String,FilePath As String,LstBox As ListBox)
PushButton1 Action:
Dim dlg as OpenDialog
Dim f as FolderItem
Dim fName,pName As String
dlg=New OpenDialog
dlg.InitialDirectory = Volume(0).Child(“Desktop”)
dlg.Title = “Select a CSV text file”
dlg.Filter = “Text Documents (*.txt)” // file type defined in File
f=dlg.ShowModal()
If f <> Nil then
fName = f.Name
pName = f.AbsolutePath //THIS WORKS !!
//pName = f.NativePath //THIS DOESN’T WORK AND SO IS COMMENTED OUT?
ImportList(fName,pName,Window1.ListBox1)
Else
//User Cancelled
exit
End if
Method ImportList Code:
Dim f as FolderItem
Dim TextIn As TextInputStream
Dim count,i,r, x As Integer
Dim line,c,s As String
I don’t understand that explanation and, so, want to stir the pot. Your original question, Stuart, involved the first part of your code where you claim that .nativepath doesn’t work. I ran the following code (with the noted changes) and the full path to my file displayed correctly in the msgBox. I think something else is wrong with your code.
Dim dlg as OpenDialog
Dim f as FolderItem
Dim fName,pName As String
dlg=New OpenDialog
//dlg.InitialDirectory = Volume(0).Child("Desktop")
dlg.InitialDirectory = SpecialFolder.Desktop
dlg.Title = "Select a CSV text file"
//dlg.Filter = "Text Documents (*.txt)" // file type defined in File
dlg.Filter = FileTypes1.Text
f=dlg.ShowModal()
If f <> Nil then
fName = f.Name
'pName = f.AbsolutePath //THIS WORKS !!: Clary: but is deprecated
pName = f.NativePath //THIS DOESN'T WORK : Clary: It does for me
'ImportList(fName,pName,Window1.ListBox1)
MsgBox pName
Else
//User Cancelled
exit
End if
The error is in his IMPORTLIST procedure (which you did not execute)
and for which he did not provide the Signature, but is passing in a STRING version of the folder path.
Because in the original code he is passing in a deprecated ABSOLUTEPATH, the line
f = GetFolderItem(FilePath)
fails because a proper path TYPE was not specified
if you make the change the you have indicated as “works” [nativepath]
then the line above must be
f = GetFolderItem(FilePath,FolderItem.PathTypeNative)
Why convert the FolderItem to a path and then back to a FolderItem again? Just have ImportList accept a FolderItem as its first parameter and pass it the result from the OpenDialog (dlg.ShowModal).