|
|||
The Extended Documentation project is designed to explain some of the more complex tools and features in SuperCard's armoury. Thanks to the patience and skill of the authors, some of the more powerful features of SuperCard have been revealed. |
||
|
AUTHOR Mark Lucas USAGE Dir( folderPath [ ,showInvFlag [ ,descendFlag [ ,delimiter(s) [ ,returnType [ ,typeOrCreator]]]]]) put Dir("My HD:MyFolder:") into dirList put Dir("My HD:MyFolder:",true,true,tab&cr,"folders") into folderList put Dir("My HD:MyFolder:",false,true,tab&cr,"type","TEXT") into textFileList DESCRIPTION The Dir external function (XFCN) is used to get the directory listing from any folder path, and to provide a variety of additional information on the files and folders in the listing. COMMENTS The Dir XFCN takes 6 parameters. All but the first are optional. These parameters are: Parameter Description folderPath This parameter contains the full path to the disk or folder from which the contents will be listed. You may include the trailing colon character (which is ordinarily part of a folder path) or not; Dir will automatically add one if you don't provide one. showInvFlag (optional) This parameter defines whether Dir should return invisible files/folders in the returned list. If this parameter is set to true, the returned list will contain files and/or folders which are invisible in the Finder (such as Desktop files or custom icons). If this parameter is set to false, invisible files/folders will not be returned in the list. The default for this parameter is false if it is not passed, or if empty or blank ("") is passed. descendFlag (optional) This parameter defines whether Dir should get the contents of sub-folders of folderPath. If this parameter is set to true, Dir will recursively descend into sub folders and return the full pathnames to their contents as well as the contents of the folder supplied in folderPath. Dir will also return complete pathways for any files or folders found, instead of just the names of the files/folders. If this parameter is set to false, only the contents of folderPath will be returned. The default for this parameter is false if it is not passed, or if empty or blank ("") is passed. delimiter(s) (optional) This controls whether Dir returns other information besides item names, and what characters are used to separate items in the returned list. If this parameter is omitted or empty, it defaults to a carriage return. If it contains (or defaults to) a single character, Dir will return just the names of the items in folderPath, separated by that character. If it contains two characters, Dir will also return a variety of information about each item in folderPath. The first character will be used to separate the 'lines' of the returned list, and the second character to separate the items on each line. Each line of this long form of the returned list is called an infoRecord. The infoRecord for a file contains 14 items:
* Note that a file's size as shown in the Finder is the physical length, whereas the actual length of its contents is the logical length. For an explanation of the differences between physical and logical file sizes, see Special Considerations, below. The infoRecord for a folder contains 8 items:
returnType (optional) This parameter determines what kind of information will be returned (files, folders, specific file types, etc.). Note that this may or may not include invisible files/folders, depending on the value of showInvFlag. The parameter can contain one of the following five strings:
The default for this parameter is "All" if it is not passed, or if empty or blank ("") is passed. typeOrCreator (optional) If the string passed for returnType is "Type" or "Creator", this parameter contains the four-character Type or Creator code, whichever is appropriate. This parameter is ignored if returnType is not "Type" or "Creator". Note that the four-character code must be exactly four characters, and is case sensitive. The following example shows how to use Dir to create a menu based on the contents of a folder. In this instance, the folder is called Extras and is located in the same folder as the main project, and calls a central DoExtra handler to execute the Extra: on MakeExtrasMenu
on MakeExtrasMenu
function GetHierarchy folderPath
As an external function, Dir will return the file or folder list if it executes successfully. If there is an error, the first line of the data that is returned will be false, and the second line will contain the error condition. SPECIAL CONSIDERATIONS Dir automatically filters out the carriage return at the end of the 'Icon\r' files which are used by the Finder for custom icons, but be aware that some file names may still contain unexpected chars. Fortunately most such oddball files are also invisible. You should put a sanity check in your scripts (which counts the number of items per line) when using the multi-item (i.e., two-delimiter) format. The only completely safe delimiter is colon (:) (since it can't be used in filenames), but can be difficult to parse when using the multi-item (i.e. two-delimiter) format. It is suggested that you use tab as the item delimiter and return as the line delimiter in these cases. When recursively descending through files and folders, Dir will retrieve the files and folders in alphabetical order (as would be displayed in the Finder), and will follow each folder that it encounters to its full depth before returning. To better understand this, you can switch to the Finder and open a folder that contains other folders. Set the view to By Name, and toggle open all the folder triangles until the hierarchy is completely expanded. This list (in the order displayed) would be what Dir returns. A sample of this is displayed below: * List returned by Dir:
To understand the difference between physical and logical file sizes, one needs to understand how files are stored on the Macintosh. Each volume contains a certain number of spaces (called blocks) that are used to store files. The size of each block (the block size) is determined by the MacOS HFS file system, which places a maximum limit on the number of blocks that a volume may contain. The larger the capacity of the volume, the larger the block size; for example, a 2GB hard disk uses 19K blocks, whereas a 250MB hard disk uses 5K blocks. Only whole blocks may be allocated when storing files, so that a file may take up one or more whole blocks on the disk. If you had a 2GB disk and created a blank document in SimpleText, when you saved it, the file would take up one complete block. If you were to Get Info on the file in the Finder, you would see that the dialog would display this information:
This means that the file is occupying one 19K block, but only 332 bytes of data are contained in the file. The physical size of this file is 19K; the logical size of this file is 332 bytes. If you had a file stored on this 2GB volume whose logical size was 20,100 bytes, its physical size would be 38K (two 19K blocks), since only whole blocks may be allocated when storing files. However, the same file stored on a 250MB volume would only take 25K (five 5K blocks). As you can see, the bigger the volume, the more of its overall capacity goes to waste. ERROR CONDITIONS If you pass a path for folderPath that does not exist, the second line of the result function will contain the string No such folder. If you pass a value for returnType that is not one of the strings supplied above, the second line of the result function will contain the string Invalid command -> (the name of the invalid command). |
||