Last modified: 2013-2-27
Class Folder
The Folder object is a js “external object” defined in the Max object called jsfolder. It is used to iterate
through Files in a folder.
Folder in Cycling '74 Reference
Constructor Attributes | Constructor Name and Description |
---|---|
Folder(pathname)
pathname can either be the name of a folder in the search path or a complete pathname using Max path syntax.
|
Field Attributes | Field Name and Description |
---|---|
Number get |
The total number of files of the specified type(s) contained in the folder.
|
Boolean get |
Non-zero (true) if there are no more files to examine in the folder, or if the pathname argument
to the Folder object didn’t find a folder.
|
String get |
The extension of the current file's name, including the period.
|
String get |
The name of the current file.
|
String get |
The four-character code associated with the current file's filetype.
|
Array get |
An array containing the values year, month, day, hour, minute, and second with the
last modified date of the current file.
|
String get |
The full pathname of the folder.
|
String Array get/set |
The list of file types that will be used to find files in the folder.
|
Method Attributes | Method Name and Description |
---|---|
void |
close()
Closes the folder.
|
void |
next()
Moves to the next file.
|
void |
reset()
Start iterating at the beginning of the list of files.
|
Class Detail
Folder
(pathname)
pathname can either be the name of a folder in the search path or a complete pathname using Max path syntax.
After creating a Folder object, you'll probably want to restrict the files you see while traversing it by setting the typelist property
Check the file max-fileformats.txt inside the init folder in the Cycling ’74 folder for filetype codes and their associated extensions. As a Folder object traverses through the files, you can find out information about the current file using its file properties. You can also determine whether you've looked at all properties by testing the end property. The following code prints the names of all files found in the folder.
To finish with the Folder object, you can either delete it, or send it the close message if you might want to reuse it.
After creating a Folder object, you'll probably want to restrict the files you see while traversing it by setting the typelist property
Check the file max-fileformats.txt inside the init folder in the Cycling ’74 folder for filetype codes and their associated extensions. As a Folder object traverses through the files, you can find out information about the current file using its file properties. You can also determine whether you've looked at all properties by testing the end property. The following code prints the names of all files found in the folder.
To finish with the Folder object, you can either delete it, or send it the close message if you might want to reuse it.
- Example:
// would try to find the patches folder in the search path f = new Folder("patches"); // uses an absolute path f = new Folder("Disk:/folder1/folder2"); // After creating a Folder object, you'll probably want to restrict // the files you see while traversing it by setting the typelist property. // // typical max files f.typelist = [ "iLaF" , "maxb" , "TEXT" ]; // post all files while (!f.end) { post(f.filename); post(); f.next(); } // close folder f.close ();
- Parameters:
- {String} pathname
Field Detail
{Number get}
count
The total number of files of the specified type(s) contained in the folder.
- Example:
f = new Folder("patches"); post(f.count); post(); f.close();
{Boolean get}
end
Non-zero (true) if there are no more files to examine in the folder, or if the pathname argument
to the Folder object didn’t find a folder.
- Example:
f = new Folder("patches"); while (!f.end) { post(f.filename); post(); f.next(); } f.close();
{String get}
extension
The extension of the current file's name, including the period. If there are no characters
after the period, a nil value is returned.. (Current file property)
- Example:
f = new Folder("patches"); while (!f.end) { post(f.extension); post(); f.next(); } f.close();
{String get}
filename
The name of the current file. (Current file property)
- Example:
f = new Folder("patches"); while (!f.end) { post(f.filename); post(); f.next(); } f.close();
{String get}
filetype
The four-character code associated with the current file's filetype. These codes are listed
in the file max-fileformats.txt, which is located at /Library/Application Support/Cycling ’74
on Macintosh and C:\Program Files\Common Files\Cycling ’74 on Windows. If there is no mapping
for the file's extension, a nil value is returned. (Current file property)
- Example:
f = new Folder("patches"); while (!f.end) { post(f.filetype); post(); f.next(); } f.close();
{Array get}
moddate
An array containing the values year, month, day, hour, minute, and second with the
last modified date of the current file. These values can be used to create a
Javascript Date object. (Current file property)
- Example:
f = new Folder("patches"); while (!f.end) { post(f.moddate); post(); f.next(); } f.close();
{String get}
pathname
The full pathname of the folder.
- Example:
f = new Folder("patches"); post(f.pathname); post(); f.close();
{String Array get/set}
typelist
The list of file types that will be used to find files in the folder.
To search for all files (the default), set the typelist property to an empty array.
- Example:
f = new Folder("patches"); post(f.typelist.toString()); post(); f.close();
Method Detail
{void}
close
()
Closes the folder. To start using it again, call the reset() function.
- Example:
f = new Folder("patches"); while (!f.end) { post(f.filename); post(); f.next(); } f.close();
{void}
next
()
Moves to the next file.
- Example:
f = new Folder("patches"); while (!f.end) { post(f.filename); post(); f.next(); } f.close();
{void}
reset
()
Start iterating at the beginning of the list of files. Re-opens the folder if it was
previously closed with the close() function.
- Example:
f = new Folder("patches"); f.close(); // reopen folder f.reset(); while (!f.end) { post(f.filename); post(); f.next(); } // reset filepointer to first file f.reset(); while (!f.end) { post(f.filename); post(); f.next(); } f.close();