Hello,
I have some doubts regarding folders. For exampleI understand the use of …SpecialFolder.Documents.Child…
How do you code the path to save/open a folder that does not belong to SpecialFolder (say, a folder within somewhere else, for example in DropBox or other places)?
SpecialFolder is a container for each of the Standard platform specific folders. So Documents is the usual place for a user to store documents, etc. Things that aren’t standard would have to be approached in a different way. If the folder you are after is within a standard location, such as Documents/DropBox then you can use .Parent and .Child methods to navigate up and down the folder hierarchy.
// Assuming it would be "Documents/DropBox"
Var oDocuments as FolderItem = SpecialFolder.Documents
Var oDropBox as FolderItem = oDocuments.Child( "DropBox" )
// If it was DropBox as a folder next to Documents you could use:
Var oDocuments as FolderItem = SpecialFolder.Documents
Var oDropBox as FolderItem = oDocuments.Parent.Child( "DropBox" )
Sure, we could unwind that to a series of checks and Child calls, but a simple question calls for a simple answer. The question was, what do I do if the file isn’t in any of the SpecialFolder locations? The answer is, use New FolderItem.
Doubts in how to deal with folders that do not belong inside Documents or any SpecialFolder.
Say my target folder has a path like: Users\DropBox\BigFolder\MyFolder, how do I address it to save and/open a file within MyFolder. I cannot use SpecialFolder.Documents.…
By the way, I use an iMac
Its simple: ask the user where the folder is and store its path. Before using the path, check if it exists…
And keep in mind, that hardened runtimes and sandboxed apps cannot save to any folder outside the sandbox without a dialog…
Good day Tim,
I’m sorry Ineed your help again.
I followed your suggestion as far as addressing a folder not belonging to SpecialFolder family and it works if you use it to save/retrieve data via BinaryStream.
What if I put an SQLite DB inside said folder and want to reach it? How do I address it?
Thanks again in advance
Hello Tim,
I added this:
AutoFldr = new FolderItem (“/Users/shep201/MEGAsync/CASA iMac/ANNO IN CORSO/CASA/AUTO/DATI AUTO/Auto.db”, FolderItem.PathModes.Native),
I tried with …/Auto.sqlite but in both cases I get a NilObjectException error
Var f As FolderItem
Try
// replace the path with your reall path
f = new folderitem("/mypath/to/the/folder/myfilename", FolderItem.PathModes.Native)
If Not(f = Nil) Then
If f.Exists then
// Your code to open the file, move the file or some other file operation goes here.
// What follows is opening a a text file example:
Var t As TextInputStream
t.Encoding = Encodings.UTF8 //specify encoding of input stream
TextArea1.Text = t.ReadAll
t.Close
Else
MessageBox("The FolderItem des not exist in the path specified, the File Open operation Failed")
End If
Else
MessageBox("The FolderItem was Nil. The File Open operation Failed")
End If
Catch e As IOException
MessageBox("Error Number: " + e.ErrorNumber.ToString + " Error Description: " + e.Message)
End Try