FolderItem question...

I have the following code:
(this portion is if a Linux OS is detected; it changes the - character to a “”)

Dim rstDataDir As RecordSet=data.SQLSelect("SELECT datadir FROM MANAGER")
Dim tDataDir As String
tDataDir = rstDataDir.field("datadir").StringValue
tDataDir = replaceall(tDataDir,"-","\")
dim dlenght as integer
dlenght = len(tDataDir) +1
tDataDir = tDataDir.Mid(0,dlenght)
'MsgBox tDataDir
selectedDir= new FolderItem(tDataDir, FolderItem.PathTypeNative)
u = selectedDir.Count

the code is to set a default directory, then opens a file selection dialog. It almost works, but it does not go down into the final directory that is stored in the tDataDir string… For example, I want to open the direcotory /home/user/Documents/directoryA/DirectoryB

The dialog box will only go down as far as DirectoryA, not the final directory of DirectoryB… Is there a limit to the number of nested directories that can be passed by the tDataDir string to the FolderItem command? Or do I need to modify the line selectedDir= new FolderItem(tDataDir, FolderItem.PathTypeNative) somehow?

Just a detail. When you post code, please select it and click the code icon above the editor. That makes it MUCH more legible :

Dim rstDataDir As RecordSet=data.SQLSelect("SELECT datadir FROM MANAGER") Dim tDataDir As String tDataDir = rstDataDir.field("datadir").StringValue tDataDir = replaceall(tDataDir,"-","\") dim dlenght as integer dlenght = len(tDataDir) +1 tDataDir = tDataDir.Mid(0,dlenght) 'MsgBox tDataDir selectedDir= new FolderItem(tDataDir, FolderItem.PathTypeNative) u = selectedDir.Count

Why would you swap - to \ ?
The \ is the “escape” character not the path separator on Unix
Linux & Unix use /

There’s a few issues that might be causing problems, but no, FolderItem isnt limited to a certain depth of folder.

dim dlenght as integer dlenght = len(tDataDir) +1 tDataDir = tDataDir.Mid(0,dlenght) 'MsgBox tDataDir

All that code literally does nothing in terms of tDataDir. I don’t know what you’re trying to achieve there.

tDataDir = replaceall(tDataDir,"-","\")

If you are trying to escape your path some how by storing spaces as -'s, don’t use - as that is a valid character for a path.

Mid starts at 1, not at 0, you might be corrupting your string some how, I’d check that.

Norman,

The string is stored in a mysql database and the sql statement did not like the \ characters…

Julian,
the '+1 " part of the code I put in to test if it was getting an extra character… I had taken out, but pasted the test code by mistake.; however, change the 0 to a 1 did fix the problem.

Thanks!

Glad you got it working :slight_smile:

Ah in that case replace \ with \\ and reverse it from \\ to \ when you read out of the database, that should do the trick.

See https://dev.mysql.com/doc/refman/5.7/en/string-literals.html table 10.1 about half way down the page for the reason.

or use prepared statements to put the data in and skip all the need for doing replacements of any kind

suppose someone has a file in a path like
“\foo\foo - bar”
if you replace all the - with \ and reverse that then you will break the file path and name
you’d put in
“-foo-foo - bar”
and when you pull it out and replace the - with \ you’d get
“\foo\foo \ bar”
which is not what you had originally

https://documentation.xojo.com/index.php/MySQLPreparedStatement