stsGetFileListing
|
|
stsGetFileListing(folderName[,filterType[,isRecursive[,includeInvisibles]]])
put stsGetFileListing("/Users/kenray/MyFolder")
put stsGetFileListing("/Users/kenray/MyFolder",".jpg","true")
Gets a list of full paths to files. You can format the result using stsFormatFileListing.
- folderName is the path to the folder from which you want the listing.
- filterType allows you to filter the file(s) that get returned either by passing the eight character type/creator used on Macs, or the file extension (used in OS X, Windows, and Unix). If not provided, filterType is assumed to be "", and will not filter any of the files.
- isRecursive determines whether the listing should continue to wend through subfolders untile a complete hierarchical listing is returned. If not provided, isRecursive is assumed to be "false".
- includeInvisibles determines whether to return invisible files (those that start with ".") on OS X or Unix. (Under Windows, this parameter is ignored and you get all the files, hidden or not).
function stsGetFileListing pFolder,pFilterType,pIsRecursive,pIncludeInvisible put ((pIsRecursive <> "false") and (pIsRecursive <> "")) into tRecursive put ((pIncludeInvisible <> "false") and (pIncludeInvisible <> "")) into tIncludeInvisible if there is a folder pFolder then put the directory into tOldDir put _stsWalkDir(pFolder,pFilterType,tRecursive,tIncludeInvisible) into tList replace "//" with "/" in tList set the directory to tOldDir if pFilterType <> "" then switch (the platform) case "MacOS" if "." is not in pFilterType then -- assume Mac Type Code filter tList with ("*" & pFilterType) replace (tab & pFilterType) with "" in tList else -- assume file extension filter tList with ("*" & pFilterType & tab & "*") put cr after tList put replaceText(tList,tab&".*\n",CR) into tList if last char of tList is CR then delete last char of tList end if default if char 1 of pFilterType <> "." then put "." before pFilterType filter tList with ("*" & pFilterType) return tList break end switch else return tList end if else return "Error: Folder does not exist at '" & pFolder & "'." end if end stsGetFileListing function _stsWalkDir pPath,pFilterType,pRecursive,pIncludeInvisible put empty into tRetVal set the directory to pPath put 0 into tItemCount put the long files into tFiles if tFiles <> "" then repeat for each line tFile in tFiles if (pFilterType <> "") and (the platform is "MacOS") then put urlDecode(item 1 of tFile) & tab & (item -1 of tFile) into tData else put urlDecode(item 1 of tFile) into tData end if if (tFile <> ".") and (tFile <> "..") then if pIncludeInvisible <> "true" then if char 1 of tFile <> "." then put pPath & "/" & tData & cr after tRetVal add 1 to tItemCount end if else put pPath & "/" & tData & cr after tRetVal add 1 to tItemCount end if end if end repeat end if if pRecursive <> "true" then return tRetVal put the folders into tFolders repeat for each line tFolder in tFolders if (tFolder <> ".") and (tFolder <> "..") then if pIncludeInvisible <> "true" then if char 1 of tFolder <> "." then add 1 to tItemCount put _stsWalkDir(pPath & "/" & tFolder,pFilterType,pRecursive,pIncludeInvisible) after tRetVal end if else add 1 to tItemCount put _stsWalkDir(pPath & "/" & tFolder,pFilterType,pRecursive,pIncludeInvisible) after tRetVal end if end if end repeat if tItemCount = 0 then -- folder has nothing to display put pPath & "/" & cr after tRetVal end if return tRetVal end _stsWalkDir