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.