Page 1 of 1

Pubdir when

PostPosted: Wed Oct 02, 2013 2:05 pm
by BRobinsonS
I created a new small app using DBPro which is not relevent to the question but..
When I ran it on another computer it came up with 'can't find file c:/somewhere/somefile '.
Thinking that I forgot to remove the path and replace it with [Pubdir] I checked it but I had replaced it.
Removed [Pubdir] and is worked without it.

I know there are times to keep the search in the 'Pubdir' using [Pubdir] variable but,just to clarify, when should it be used and when is it not necessary.
Is it used to Extract files from Neobook too?

Re: Pubdir when

PostPosted: Wed Oct 02, 2013 2:45 pm
by dec

If I'm not wrong, you can choose where to extract your embedded files. Just when need to extract a file you need to provide a target path in order to be extracted. Anyway you can use the "[PubDir]" anytime and probably is the best option you can choose. In fact it's a bad idea to use "static" paths in our software because we cannot know if other computers have these paths availables or not. Probably not. So we need to avoid this.

So the "[PubDir]" variable is the starting point for paths relatives to your executable's. However, sometimes you need a little more than this variable. NeoBook have some other variables that allows you to know certain system paths, and plugins like npInfo allows you to know some special system paths like the user documents, the common application data path, etc. You are encourage to use this kind of variables instead hard writen paths.

Sometimes you can need a system or user path (say "My Documents", for example) because "[PubDir]" can be not the best choice. For example, supose you need to extract a file from your publication and this are executed from a CDROM. In this case you cannot use "[PubDir]" in order to write anything, because the any CDROM path are writable. In cases like this you can use the NeoBook paths or as I suggest before a plugin like npInfo.

So in conclusion (and in my honest opinion/experience):

1º Avoid the use of hard writen paths like "C:\xxx\yyy" or something else. Simply never use something like that.

2º Use "[PubDir]" always than possible, deploying your publications files accordingly (relative to your executable's).

3º When you need other paths use others NeoBook path's variables or something like npInfo to obtain the right path

Hope this can help you in some manner. ;)

Re: Pubdir when

PostPosted: Wed Oct 02, 2013 3:04 pm
by Neosoft Support
In addition to David's advice, I would just add the following:

1. Use [PubDir] when you want to access something stored in the folder where your compiled exe is located. (Note that Microsoft does not want apps to store user data or documents under Program Files anymore.)

2. For user data, documents, databases, etc., the user's Documents folder should be used instead. For example, the following code tests for and creates (if needed) a folder under Documents for storing data:

Code: Select all
.configure folder where app's data will be stored
SetVar "[DataDir]" "[MyDocuments]AppName\"
FolderExists "[DataDir]" "[Result]"
If "[Result]" "=" "False"
  .data directory does not exist, so create it
  CreateFolder "[DataDir]"

Replace "AppName" above with the name of your application.

You can the use [DataDir] instead of [PubDir] throughout the rest of your app.

Re: Pubdir when

PostPosted: Wed Oct 02, 2013 4:37 pm
by BRobinsonS
The apps I have on the go (one major) keeps and looks for data in the app's folder(not under programs), but I can see a need to keep data in a sub-directory in other projects.

I generally use [Pubdir] but I thought I would like clarification.

Thanks for the input.