Absolutepath to actual file?

This should be simple, but I can’t quite figure it out.

If I know the absolutepath for a file (which is plain text, a string), how do I get from there to the actual file itself (which is not just text but a folderitem)?

Specifically, suppose that I know that a file’s absolutepath is “C:\MyDirectory1\MyFIle” and that I want to delete that file, what is the (simplest) needed code to do that?

Barry Traver

Not tested, but this should do the job:

Dim f as FolderItem f=GetFolderItem("C:\\MyDirectory1\\MyFIle\" + yourFileName) f.Delete() If f.LastErrorCode > 0 then MsgBox Str("Error: " + f.LastErrorCode) End if

Try this…

CreatePushbutton Action Event
//Create a file and get its Shellpath
Dim myFile as folderitem
myFile = SpecialFolder.Documents.Child(“my ShellpathFile”)
If myFile <> nil then
If not myFile.exists then
Dim TOS as TextOutputStream
TOS = TextOutputStream.Append(myFile)
TOS = Nil
Dim myFileShellpath as String
myFileShellpath = myFile.Shellpath
TextField1.Text = myFileShellpath
myFile.Parent.Launch
end if
end if

DeletePushbutton Action Event
//Delete the just created file
Dim f as FolderItem
f=GetFolderItem(Textfield1.Text, FolderItem.PathTypeShell)

f.delete

If f.LastErrorCode > 0 then
MsgBox Str("Error: " + f.LastErrorCode)
End if

Lennox

MsgBox "Error: " + Str(f.LastErrorCode) // instead of MsgBox Str("Error: " + f.LastErrorCode)

Sascha,

GetFolderItem was exactly what I needed. Many thanks for the note!

Barry Traver

Thanks also to others who posted.

P,.S. Here’s a very minor correction to the code you posted:

This:

MsgBox Str("Error: " + f.LastErrorCode)

should be this:

MsgBox Str("Error: " + Str ( f.LastErrorCode) )

(since LastErrorCode is an integer).