Use of Resources folder

app.VPdata = SpecialFolder.ApplicationData.child( “OpVPdata” )
if not app.VPdata.exists then app.VPdata.createasfolder
Dest = app.VPdata.child( “Games” )
if not Dest.exists then Dest.CreateAsFolder

Thanks, Jeff. Now I’m trying to wrap my head around what is going on. In particular, why is the second line necessary when the OpVPdata folder has already been created by earlier code?

I don’t think it has.

Are you actually using the debugger?

Look in the applicationdata folder and check what is being created in real time.
And don’t assume everything is fine if it works once.
delete the folder and contents so that you recreate the user’s experience of an empty system when testing.

[quote=433565:@Jeff Tullin]I don’t think it has.

Are you actually using the debugger?

Look in the applicationdata folder and check what is being created in real time.
And don’t assume everything is fine if it works once.
delete the folder and contents so that you recreate the user’s experience of an empty system when testing.[/quote]

Yes, I’m using the debugger.

How do I find the applicationdata folder?

http://documentation.xojo.com/api/files/specialfolder.html

[quote]ApplicationData
Windows: \Users\UserName\AppData\Roaming\
MacOS : /Users/UserName/Library/Application Support
Linux: /home/UserName/Applications
[/quote]

Thanks, but I still can’t find it
I’m on El Capitan (OS 10.11.6) which is the latest that will run on this computer.
In Users there is Dan and Shared
In Dan there are a lot of things, but no Library
In Shared there is Library, which contains ApplicationSupport, which contains only Adobe
I can’t find ApplicationData or OpVPdata anywhere

At the top level, next to Users, there is a Library which contains Application Support, but there is no OpVPdata folder. The code to create it is:

app.VPdata = SpecialFolder.ApplicationData.child( "OpVPdata" )
if not app.VPdata.exists then app.VPdata.CreateAsFolder

I looked at Permissions on Library. It’s Read&Write for system but Read only for others, and it won’t let me change it.

[quote=433594:@Dan Paymar]Thanks, but I still can’t find it
In Dan there are a lot of things, but no Library
[/quote]
Open a Finder window and go to your home folder.
Click on the Go menu with the Option/ Alt key pressed.
Now there will be a menu choice Library and you will be able to go to Application Support (=ApplicationData).

If you want to have the Library choice always in the Go menu, you can do following:
When in your Finder home folder, select menu choice View --> Show View Options and check ‘Show Library Folder’
Now Library will always be shown in the Go menu

Thanks, Paul. I couldn’t find an option to always show the Library folder, but with the Option key I did get into the Library folder and find my OpVPdata folder. It does contain a Games folder, but inside that is a nested Games folder which does contain my games files.

How did I get nested Games folders? The code is:

app.VPdata = SpecialFolder.ApplicationData.child( "OpVPdata" )
if not app.VPdata.exists then app.VPdata.CreateAsFolder
Dest = app.VPdata.child( "Games" )
if not Dest.exists then Dest.CreateAsFolder
Source = GetFolderItem( "Games" )
x = CopyFileOrFolder( Source, Dest )
if x = false then return false

In the main menu bar with the Finder in the foreground select Go > Home
then in the menu bar select View > Show View Options
there should be an option to Show Library Folder

In the Finder, press the Go Menu, press the Option Key and you will see a Library MenuItem; search your folder from there.
One you found the folder you want, make an alias beside your Project file so you will have it on hand.

Another idea is to add a MenuItem (temporary) in your application MenuBar (Help for example) that will display the folder you want to open. You already have a FolderItem on it (read the FolderItem entry in the docs for the code [FolderItem.Launch I think]). This will be removed before building the application to be released.

Be a developer is also be a creative person. Do the minimum and let the computer do the rest :wink:

[quote]Inside that is a nested Games folder which does contain my games files.
How did I get nested Games folders?[/quote]

You don’t know?

CopyFileOrFolder( Source, Dest )

You have copied a folder called Games into the destination folder - which is called Games.

Ahhhh! Thanks to all of you, I’ve learned a lot, and I finally got it working to create the OpVPdata folder and copy my three data folders to it.

Well, almost. It doesn’t work if the OpVPdata folder already exists.

I suppose the best thing to do would be to check whether it already exists, and if so, delete it.

[quote=433639:@Dan Paymar]Well, almost. It doesn’t work if the OpVPdata folder already exists.
[/quote]
It should work. What’s the code look like now? The code previously posted will work whether OpVPdata exists or not.

That sounds like a really bad idea. Fix your code instead.

If it exists, then don’t create it and copy the data folders in - ta dah!

If it exists, don’t create it. Then check for the existence of each of the data folders within and only copy in those that are missing.

I don’t agree.
Although the file may exist, the file to be copied into that data folder can be newer and contain updated data that is needed by the application.
There are 2 possibile solutions:

  1. Always replace the files in the data folder(s)
  2. Only update when the creation/modification date is newer compared to the existing file. (This only works when the files aren’t updated frequently by the application)

I don’t know what the files are, but you don’t want to destroy the work of the user.

[quote=433429:@Tim Hare]Don’t use the path. Save a folderitem pointing to your folder in ApplicationData and use Child to get to the specific file in the folder.

app.StuffFldr = SpecialFolder.ApplicationData.Child(""OpVPdata" )

elsewhere,

f = app.StuffFldr.Child("some file") [/quote]

This is going fine so far. My pointer is app.VPdata. But I’m having trouble with the syntax to:
Create a new folder in VPdata
Create a new text file within a folder in VPdata
Delete a file within a folder in VPdata

I tried copying parts of the Copy function, but I’m having trouble. Examples would be appreciated.