What's the syntax to check if a local folder exists?
Jim Ault
jimaultwins at yahoo.com
Tue Jun 7 11:42:30 EDT 2011
On Jun 7, 2011, at 7:37 AM, Keith Clarke wrote:
> Great, thanks to all who responded!
> Blindingly obvious once viewed with hindsight - and as Colin rightly
> suggests, it seems 'there is' still much I need to learn about the
> subtleties of the LiveCode syntax! ;-)
>
> I went for a matching pair of one-liners, which worked very nicely:
> if there is not a folder "this_folder" then create folder
> "this_folder"
> if there is not a folder "this_folder/that_subfolder" then create
> folder "this_folder/that_subfolder"
>
In case someone has a more complex set of conditions,
here are two ways I create a folder/subfolder structure
on openstack to insure folders exist when needed,
especially in a new drive or computer location.
The first is a single path for all log files
The second is a split path for multiple users
The create folder only works with one folder level at a time, so
------- Single Path ----------
--start with a known root folder location
-- note that I use 'pathh' as my working variable
local xPathhMsgs, xMsgSource
on initMsgProcessing --7.25.06
put rootLocalFolder() into pathh
--define successive path names
replace "Projects/merge/" with "Projects/logs/" in pathh
if there is not a folder pathh then create folder pathh
replace "logs/" with "logs/msgProc/" in pathh
if there is not a folder pathh then create folder pathh
replace "msgProc/" with "msgProc/merge/" in pathh
--keep the old path (like prev day) as archive
--then do this
put pathh & the seconds into pathh2 -- make old name
if there IS a folder pathh then
rename folder pathh to pathh2 --
end if
-- now yesterday's folder is unique
-- and restarting in the same day will keep old logs
-- now let's make the empty folder for today
if there is not a folder pathh then create folder pathh
put pathh into xPathhMsgs -- keep this pathh
end initMsgProcessing
------- Multiple Paths ----------
--start with a defined root folder location
-- note that I use 'pathh' as my working variable
global zRootLocalFolder
on makeFolders whichFldr
--build archiving folders for email activity
put zRootLocalFolder into pathh
if not there is a folder pathh then create folder pathh
-- user account specific folders MAKE them
put
"EmailsSent
,keepTheseFiles
,logs
,logs_vidLibWebPages/,logs_vidLibWebPages/,IDtablesZZZ,IDtablesZZZ/
pageID,IDtablesZZZ/urlID,IDtablesZZZ/emailListID" into repeatStrngs
-- add user designation to 4 sub folders
replace "ZZZ" with whichFldr in repeatStrngs
repeat for each item ITM in repeatStrngs
if not there is a folder (pathh&ITM) then create folder
(pathh&ITM)
end repeat
-----
-- here is what the loop will do
-- if not there is a folder (pathh&"EmailsSent") then create
folder (pathh&"EmailsSent")
-- if not there is a folder (pathh&"keepTheseFiles") then create
folder (pathh&"keepTheseFiles")
-- if not there is a folder (pathh&"logs") then create folder
(pathh&"logs")
-- if not there is a folder (pathh&"logs_vidLibWebPages/") then
create folder (pathh&"logs_vidLibWebPages/")
-- if not there is a folder (pathh&"IDtables") then create
folder (pathh&"IDtables")
-- if not there is a folder (pathh&"IDtablesZZZ/pageID") then
create folder (pathh&"IDtables/pageID")
-- if not there is a folder (pathh&"IDtables/urlID") then create
folder (pathh&"IDtables/urlID")
-- if not there is a folder (pathh&"IDtables/emailListID") then
create folder (pathh&"IDtables/emailListID")
--inserting whichFldr param into IDtablesZZZ
--IDtablesZZZ/pageID
-- IDtablesZZZ/urlID
-- IDtablesZZZ/emailListID
end makeFolders
Hope this helps someone
Jim Ault
Las Vegas
More information about the use-livecode
mailing list