GetNthFileNameInFolder
From Director Online Wiki
importFileInto
| |
---|---|
Type: | Movie method |
Version: | ? |
Language: | Lingo, JavaScript |
Dependencies: | none |
Links/Related | |
fileName, importFileInto(), fileIO xtra |
Returns "" or the name of a file or folder in the given folder.
Syntax
from MX 2004 Documentation
vFileName = getNthFileNameInFolder(absolute path to folder, positive integer file number)
Examples
on getListOfFilesInFolder(aFolderPath, aRecursive) ------------------- -- INPUT: <aFolderPath> should be a string absolute path to a folder -- <aRecursive>, if it is TRUE, will add the contents of all -- subfolders to the output list -- OUTPUT: Returns a property list with the format: -- [<string file name>: 0, -- <string folder name>: [<string file name>: 0, ...] -- <string empty folder name>: 0, -- ...] -- NOTE: If aRecursive is not TRUE, then both files and folders -- will have a value of 0. If aRecursive is TRUE, then -- non-empty folders will have a property list as their -- value; files and empty folders will have a value of 0. -------------------------------------------------------------------- if not stringP(aFolderPath) then return #stringFolderPathExpected end if aRecursive = (aRecursive = TRUE) if aRecursive then -- Ensure that aFolderPath ends with the platform-specific -- folder delimiter if the platform starts "Win" then vDelimiter = "\" else vDelimiter = ":" end if if the last char of aFolderPath <> vDelimiter then put vDelimiter after aFolderPath end if end if -- Iterate through the folder vFileList = [:] n = 0 repeat while TRUE n = n + 1 vFileName = getNthFileNameInFolder(aFolderPath, n) if vFileName = "" then -- There are no more items in this folder return vFileList end if if aRecursive then -- Check if this "file" is actually a non-empty folder vFolder = aFolderPath&vFileName&vDelimiter vContents = getListOfFilesInFolder(vFolder, TRUE) if not vContents.count then vContents = 0 end if else vContents = 0 end if vFileList.addProp(vFileName, vContents) end repeat return vFileList end getListOfFilesInFolder
on getTypedFilesInFolder(aFolderPath, aExtension) -------------------- -- INPUT: <aFolderPath> should be a string absolute path to a folder -- <aExtension> should be a string extension, such as "txt" -- OUTPUT: Returns a linear list with the format... -- [<string file name>, ...] -- ... where all the file names have the given extension. -------------------------------------------------------------------- if not stringP(aFolderPath) then return #stringFolderPathExpected else if not stringP(aExtension) then return #stringExtensionExpected end if -- Remove any leading dots repeat while (aExtension starts ".") delete char 1 of aExtension end repeat the itemDelimiter = "." -- Iterate through the folder vFileList = [] n = 0 repeat while TRUE n = n + 1 vFileName = getNthFileNameInFolder(aFolderPath, n) if vFileName = "" then -- There are no more items in this folder return vFileList end if if the last item of vFileName = aExtension then vFileList.append(vFileName) end if end repeat return vFileList end getTypedFilesInFolder
See also
fileName, importFileInto(), FileIO xtra