Page 1 of 1
Error Creating Folders with Standalone in WinXP
Posted: Fri Sep 13, 2013 3:02 am
by buchacho
This script works before creating a standalone, I am trying to create folders to write files to in an organized fashion:
Code: Select all
if the hilite of btn "WriteFile" is true then
if there is not a folder folderPath then
create folder folderPath
if the result is not empty then
answer "Couldn't create folder."
break
end if
end if
end if
It works while I am developing the app, but not as a standalone for WinXP. I am also wondering if I will have a problem writing individual files.
Re: Error Creating Folders with Standalone in WinXP
Posted: Fri Sep 13, 2013 9:22 am
by SparkOut
There may be other answers, but my first guess would be to check the folderPath. In a standalone the default path is relative to the standalone location, while in the IDE the default path is relative to the LC engine. If you have constructed the folderPath contents from the default folder in the IDE it may not match the where the standalone attempts to create the directory. You may also be running against permission problems in creating folders in restricted areas (eg Program Files directory)
Re: Error Creating Folders with Standalone in WinXP
Posted: Fri Sep 13, 2013 11:11 am
by Klaus
Hi Buchacho,
let you show the possible error:
Code: Select all
...
create folder folderPath
if the result is not empty then
answer "Couldn't create folder." & CR & THE RESULT
break
end if
...
This may give you a hint. I guess you don't have write permission in the target folder?
Best
Klaus
Re: Error Creating Folders with Standalone in WinXP
Posted: Fri Sep 13, 2013 6:00 pm
by buchacho
I should have included this info for folderPath:
Code: Select all
put the effective filename of this stack into tPath
set the itemDelimiter to slash
delete last item of tPath
put tPath & slash & "AutoFiles" & slash & "AutoFiles" & formattedDate & slash into folderPath
I have not tried the suggestions yet...
Re: Error Creating Folders with Standalone in WinXP
Posted: Fri Sep 13, 2013 6:09 pm
by Klaus
Hi buchacho,
maybe your current user does not have write permissions in the folder where your standalone resides?
Use -> specialfolderpath("documents") or -> specialfolderpath("home") instead!
Best
Klaus
Re: Error Creating Folders with Standalone in WinXP
Posted: Fri Sep 13, 2013 7:01 pm
by SparkOut
This line looks like the main problem to me (apart from ensuring that the user has write permissions for the location)
Code: Select all
put tPath & slash & "AutoFiles" & slash & "AutoFiles" & formattedDate & slash into folderPath
You cannot create more than one folder at a time. If the parent folder "Autofiles" does not already exist, then LC cannot create the subfolder "Autofiles&formattedDate". You will need to test for the existence of the tPath & slash & "Autofiles" folder first, and create it if it does not already exist, and
then test for the existence of the "Autofiles&formattedDate" subfolder.
But in any event, save the files into a designated program data folder eg specialFolderPath(26) or specialFolderPath(28).
See
http://www.sonsothunder.com/devres/revo ... ile010.htm
Re: Error Creating Folders with Standalone in WinXP
Posted: Fri Sep 13, 2013 8:42 pm
by buchacho
I see some good suggestions here (thanks!). I first had it create one folder, and then later decided to add a subfolder with a date/timestamp so that first folder was still there after I added more to the original code. Edit: I added the first subfolder and re-ran my standalone app and it worked! So yes, creating two directories at once looks to be the problem.
One more question I have, is there a way to specify the folder location so that it works while I develop and in the standalone? I think I saw an example of how to execute certain code depending on if you are in dev or standalone with an if statement, but now I am not sure.
Re: Error Creating Folders with Standalone in WinXP
Posted: Sat Sep 14, 2013 10:19 am
by SparkOut
Use an app data directory regardless! But you can execute different code by checking "the environment":
Code: Select all
if the environment is "development" then
doSomethingInTheIDE
else if the environment is "standalone application" then
doSomethingAsStandalone
end if
Or perhaps more elegantly
Code: Select all
switch
case the environment is "development"
doYourIDEThingHere
break
case the environment contains "application"
doYourStandaloneThingHere
--note "standalone application" and "helper application" are both standalones, the "helper" has secureMode set to true. You could test for both separately if it makes a difference to you.
break
end switch
Re: Error Creating Folders with Standalone in WinXP
Posted: Sat Sep 14, 2013 4:29 pm
by FourthWorld
In addition to the other great suggestions here, this function may help - you pass it a path, and it ensures that each folder in the path exists, creating a new one where needed, reporting errors if it's unable to complete. This is especially helpful when you need to create multiple nested folders in one move:
Code: Select all
--
-- stdEnsurePath
--
-- Checks the path specified in pPath to make sure each of its
-- directories exists, creating any that need to be as it goes.
--
on stdEnsurePath pPath
set the itemdel to "/"
--
put item 1 of pPath into tTestPath
put pPath into tDestFolders
delete item 1 of tDestFolders
repeat for each item tFolder in tDestFolders
put "/"&tFolder after tTestPath
if there is not a folder tTestPath then
create folder tTestPath
Err the result, "Couldn't create folder ""e&tTestPath \
"e &" ("& sysError() &")"
end if
end repeat
end stdEnsurePath
Of special interest there is the sysError function, which LiveCode provides to return the last I/O error code as reported by the host OS. Many times getting the sysError code will help you determine whether a file I/O routine failed because of permissions, or an invalid path, or something else.