Forums > MaxMSP

Umenu autopopulate – always alphabetical order?

June 27, 2011 | 1:35 pm

Is there any way to autopopulate in order of date created?



Jan
June 27, 2011 | 11:13 pm

If you put this JavaScript code into a [js] and send it the message "read path/to/the/folder" it will output all files by date modified/created ascending.

function read(path) {
	var folder = new Folder(path);
	var allFiles = new Array();
	var i = 0;
	 while (!folder.end) {
	 var d = new Date(
			folder.moddate[0],
			folder.moddate[1],
			folder.moddate[2],
			folder.moddate[3],
			folder.moddate[4],
			folder.moddate[5],
			0);
                // sort out hidden files and folders
                // and write others into an array
		if (folder.filename && folder.filetype!="fold") {
			allFiles[i] = {name: folder.filename, date : Number(d)};
			i++;

		}
		folder.next();
	 }
         folder.close();
         // sort the array by date asc
	 allFiles.sort(
		function(a, b){
			return a.date-b.date;
		}
	);
        // and finally send the file names to outlet
	for(var j=0;j

If you want to change the order to descending change the line:
"return a.date-b.date;"

into:
"return b.date-a.date;"

jan


June 28, 2011 | 7:43 am

Wow – thank you so much for sharing this.

Awesome!



Jan
June 28, 2011 | 8:10 am

;) !


Viewing 4 posts - 1 through 4 (of 4 total)