Paths

Hi Folks,

I wrote the following in a program years ago… “Dim VicRegFile as FolderItem=GetFolderItem(”\DataFiles\VicReg.rsd")". I wrote this in an early version of RS but now it is running Real Studio 2012 release 2 and it can’t find the files. Instead of looking for \DataFiles\VicReg.rsd which hangs below the application directory, it is looking for the files in the working directory where it was written.

Any ideas?

John.

Use Parent and Child.

Dim VicRegFile as FolderItem
VicRegFile = GetFolderItem("").Parent.Child("DataFiles").Child("VicReg.rsd")

("").Parent will go back to your apps parent directory. If that’s not corrent, remove .parent.

Thank you, it worked great. Thanks for the education.

John.

It moved through the code OK but later stopped when it tried to take data from the file. It looks like it is not reading the file although the error trapping is not catching it and it appears to be loading.
This is the code;

Dim VicRegFile as FolderItem
VicRegFile = GetFolderItem("").Parent.Child(“DataFiles”).Child(“VicReg.rsd”)

VicRegister = New REALSQLDatabase
VicRegister.DatabaseFile = VicRegFile
if VicRegister.error then
msgbox "DB Error: " + VicRegister.errormessage
return
end
if not VicRegister.Connect then
Msgbox “Cannot connect to VicReg.rsd”
quit
end

When it gets to;
dim sqlSecurity as Variant = “select * from Security”
dim rsSecurity As RecordSet = Admin.SQLSelect(sqlSecurity)

VarPassword=rsSecurity.field("Password").StringValue

Try replacing the first 2 lines with the following code. The conditional pragma if/then/endif will first see if you are executing the application from the Xojo IDE, or if it is a stand-alone application. Depending on DebugBuild or Compiled executable mode, the path location will change; the pragma takes care of this. Second, if the FolderItem is not found where it’s suppose to be located, it gives an opportunity to rectify that issue :slight_smile:

[code]Dim VicRegFile as FolderItem

#if debugbuild then
VicRegFile = GetFolderItem("").Parent.Child(“DataFiles”).Child(“VicReg.rsd”)
#else
VicRegFile = GetFolderItem(“DataFiles”).Child(“VicReg.rsd”)
#endif

If IsNull(VicRegFile) then
MsgBox “Oops! The Database file was not found!”
//Create or ask user to specify the file location.
end if[/code]

Thanks, it didn’t find the file and yet it got through;

if VicRegister.error then
msgbox "DB Error: " + VicRegister.errormessage
return
end
if not VicRegister.Connect then
Msgbox “Cannot connect to VicReg.rsd”
quit
end

Is the database file opened in another instance, or within a Database Management program? SQLite databases are single-user files and the open state gets locked if it is opened in another process.

No, there is nothing using that file and this code is in the “App.Open” event so it is the first time the file is addressed.

Could there be something changed about these lines?

//GET VARIABLES
dim sqlSecurity as Variant = “select * from Security”
dim rsSecurity As RecordSet = Admin.SQLSelect(sqlSecurity)

//GET PASSWORD AND ASSIGN TO VARIABLE
VarPassword=rsSecurity.field(“Password”).StringValue

John, there are a couple of things to look at. First, remember that a FolderItem is NOT a file or folder. It is a variable structure that holds information about something. So you should always check to see if the file specified actually exists. Something like

VicRegFile = GetFolderItem("").Parent.Child("DataFiles").Child("VicReg.rsd") if VicRegFile.Exists = True then ...
and ensure that it is actually there. If it really doesn’t exist, everything you are doing after that is dealing with a database that has no data. Thus when you try to read from it, no data is returned. And, in fact, the attempt may fail.

Second, you should be checking for a DBerror after

dim rsSecurity As RecordSet = Admin.SQLSelect(sqlSecurity)

since this is the first place you actually access the data and an error here will indicate your connection to the database or the internal structure of the database is not what you expected. Again, this error might indicate that youo are not really reading from the database file.

I tried the “if VicRegFile.Exists = True then…” and it didn’t find the file. It does exist in the DataFiles directory under “C:\Program Files (x86)\Airport Utilities” as “C:\Program Files (x86)\Airport Utilities\DataFiles”. there are three files there which should, and used to, all connect.

Is there something wrong with;
VicRegFile = GetFolderItem("").Parent.Child(“DataFiles”).Child(“VicReg.rsd”)

Where’s your app in that path? In a directory in Airport Utilities?

The App is in;
“C:\Program Files (x86)\Airport Utilities”

and the data files are in;
“C:\Program Files (x86)\Airport Utilities\DataFiles”

I would be concerned about permissions. The location of your database is protected by Windows, so opening in read/write mode will cause problems. I’m assuming an rsd file is a real sqlite database.

So does the program work when run as administrator?

[quote=183704:@John Cooper]The App is in;
“C:\Program Files (x86)\Airport Utilities”

and the data files are in;
“C:\Program Files (x86)\Airport Utilities\DataFiles”[/quote]

What Wayne said :slight_smile:

But if your app is directly in Airport Utilities and not in a directory IN Airport Utilities the path is wrong.
VicRegFile = GetFolderItem("").Child(“DataFiles”).Child(“VicReg.rsd”)

Thanks everyone, and sorry about the delay replying… other computer problems now fixed.

Taking .Parent out seemed to fix it.