Desktop Create Folder

Hi all,

I would like to create folder in Windows at runtime:

  dim f as new FolderItem
  rs = app.AccountDB.GetRecord("System", 1)
  app.RootTempFolder = rs.Field("TempPath").StringValue = app.RootTempFolder

If the folder already exists, the program continues as I did not track any “folder exists error”. However, if the folder doesn’t exist, it creates the folder successful but followed by a crash in xojo. Xojo.exe stopped. Is this a bug or something?

P.S. I am using Xojo 2016r3


What is the value of app.rootTempFolder ?

f = SpecialFolder(“Desktop”).Child(rs.Field(“TempPath”).StringValue).CreateAsFolder

The only reason why that would happen I can see is that you may have used illegal characters.

But, inferring from the variable name, why do you create a temporary folder on the desktop ? Can’t you use GetTemporaryFolderItem instead ?

You will be sure that the name is legal, and unique.

The value is stored in database, in which I put “c:\xojo_temp”. I don’t think is illegal character or database problem since I hard coded the value cause the same problem.

I need a temp folder to hold temp files which are stored in blob, temporarily save them in temp folders and open them.

Use GetTemporaryFolderItem. It is the recommended way.

Then you don’t have to worry about name or location.

Please split that code in several lines.

SpecialFolder.desktop sounds more right.
Child may return nil as may the Field function.
And CreateAsFolder should create a folder. If folder exists, there is no error as that’s also a success.

Thanks all but still does not work… not even as simple as:

dim f as new FolderItem = “c:\xojo_text”

Can anyone be kind enough to share some working codes?

Further information, the code above actually creates the folder, only when I close the program, Xojo crashes. I did not test from the build exe yet.

you should not assign a path to name property.

try something like this:

[code] dim DesktopFolder as FolderItem = SpecialFolder.Desktop
dim MyFolder as FolderItem = DesktopFolder.Child(“test”)

	dim file as FolderItem = MyFolder.Child("test.txt")
	dim t as TextOutputStream = TextOutputStream.Create(file)
	t.WriteLine "Hello World"[/code]

This is an invalid name.

Also, you cannot create a folder in the root of the disk like that, you don’t have permissions.

This would work :

f = specialfolder.desktop.child("xojo_text") f.createAsFolder

Once again, use GetTemporaryFolderItem, or create your folder in SpecialFolder.Temporary. What you are doing is not recommended. The Desktop is not intended for temporary files at all.

[quote=301624:@Tony Lam]Thanks all but still does not work… not even as simple as:

dim f as new FolderItem = “c:\xojo_text”

Can anyone be kind enough to share some working codes?[/quote]

This what i do instead… check if it exist and then create the folder if it does not exist.
but then mine is checking if my folder has a subfolder called Reports.

DIM f AS FolderItem
f = GetFolderItem("").child(“Reports”)
if not f.Exists then f.CreateAsFolder

Creating folders in the Application/Program Files directories is frowned upon, and Windows virtualizes it, so best of to use the ApplicationData folder or the Temporary folder…

Thanks all for your advices.

You could also try:

dim f as folderitem = GetFolderItem("c:\\mypath", FolderItem.PathTypeNative) f.createAsFolder

This is incorrect. Use

f = GetFolderItem(app.RootTempFolder)


i know… but for my clients, i setup a folder called ARTSCENESERVER where all the stuff for the images, the databases and all the user folder in located in the subfolder under the main one.

That’s fine, so long as you’re not updating the folder (saving new files, changing existing files, etc)… If you are, use the AppData folder as recommended by the people making the operating systems :slight_smile:

i know… my application does not go to Program file folder on Windows or Applications folder on Mac.