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
f.name = app.RootTempFolder
f.CreateAsFolder
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?
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.
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.
[code] dim DesktopFolder as FolderItem = SpecialFolder.Desktop
dim MyFolder as FolderItem = DesktopFolder.Child(“test”)
MyFolder.CreateAsFolder
dim file as FolderItem = MyFolder.Child("test.txt")
dim t as TextOutputStream = TextOutputStream.Create(file)
t.WriteLine "Hello World"[/code]
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
f.name = “c:\xojo_text”
f.CreateAsFolder
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…
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