Max 5 API Reference
00001 /** 00002 @file 00003 filedate - manage search paths 00004 Accesses a file on disk and outputs a given byte of the file's data. 00005 Note that we use the "open" message, not "read", because we're not loading the file into memory. 00006 00007 updated 3/22/09 ajm: new API 00008 00009 @ingroup examples 00010 */ 00011 00012 #include "ext.h" 00013 #include "ext_obex.h" 00014 #include "ext_path.h" 00015 #include "ext_strings.h" 00016 00017 00018 typedef struct filedate 00019 { 00020 t_object f_ob; 00021 } t_filedate; 00022 00023 void *filedate_class; 00024 00025 void filedate_assist(t_filedate *x, void *b, long m, long a, char *s); 00026 void filedate_doanything(t_filedate *x, t_symbol *s, short argc, t_atom *argv); 00027 void filedate_out(t_filedate *x, unsigned long date); 00028 void filedate_anything(t_filedate *x, t_symbol *s, short argc, t_atom *argv); 00029 void *filedate_new(void); 00030 00031 t_symbol *ps_nothing, *ps_list; 00032 00033 int main() 00034 { 00035 t_class *c; 00036 00037 c = class_new("filedate", (method)filedate_new,0L, (short)sizeof(t_filedate), 0L, 0); 00038 class_addmethod(c, (method)filedate_anything, "anything", A_GIMME, 0); 00039 class_addmethod(c, (method)filedate_assist,"assist",A_CANT,0); 00040 class_register(CLASS_BOX, c); 00041 filedate_class = c; 00042 00043 ps_nothing = gensym(""); 00044 ps_list = gensym("list"); 00045 00046 return (0); 00047 } 00048 00049 void filedate_assist(t_filedate *x, void *b, long m, long a, char *s) 00050 { 00051 if (m==1) { 00052 switch (a) { 00053 case 0: sprintf(s,"File/Folder to Check Modification Date"); break; 00054 } 00055 } 00056 else if (m==2) { 00057 switch (a) { 00058 case 0: sprintf(s,"Mod Date (Month/Day/Year/Hour/Min/Sec)"); break; 00059 } 00060 } 00061 } 00062 00063 void filedate_anything(t_filedate *x, t_symbol *s, short argc, t_atom *argv) 00064 { 00065 defer(x,(method)filedate_doanything,s,argc,argv); 00066 } 00067 00068 void filedate_doanything(t_filedate *x, t_symbol *s, short argc, t_atom *argv) 00069 { 00070 char filename[MAX_PATH_CHARS]; 00071 short vol,err; 00072 long type; 00073 unsigned long date; 00074 00075 if (s == ps_nothing) 00076 return; 00077 strcpy(filename,s->s_name); 00078 if (!locatefile_extended(filename,&vol,&type,&type,-1)) { // look for all files 00079 err = path_getfilemoddate(filename,vol,&date); // find the date of the file 00080 if (err) { 00081 object_error((t_object *)x, "%s: error %d getting date",s->s_name,err); 00082 return; 00083 } 00084 filedate_out(x,date); 00085 } else { // now check for a folder, you need to copy the name again 00086 // since locatefile_extended may have changed it 00087 strcpy(filename,s->s_name); 00088 if (!path_resolvefile(filename,0,&vol)) { // returns false if it found a file or folder 00089 // the logic here is that a folder, which wouldn't be 00090 // found by locatefile_extended would be the 00091 // only thing found here 00092 err = path_getmoddate(vol,&date); // find the date of the path, not the file 00093 if (!err) { 00094 filedate_out(x,date); 00095 return; 00096 } else { 00097 object_error((t_object *)x, "%s: error %d getting date",s->s_name,err); 00098 return; 00099 } 00100 } 00101 object_error((t_object *)x, "%s: can't find",s->s_name); 00102 } 00103 } 00104 00105 void filedate_out(t_filedate *x, unsigned long date) 00106 { 00107 t_datetime dtr; 00108 t_atom list[16]; 00109 00110 systime_secondstodate(date,&dtr); // convert the date to a readable record 00111 atom_setlong(list,dtr.month); 00112 atom_setlong(list+1,dtr.day); 00113 atom_setlong(list+2,dtr.year); 00114 atom_setlong(list+3,dtr.hour); 00115 atom_setlong(list+4,dtr.minute); 00116 atom_setlong(list+5,dtr.second); 00117 outlet_list(x->f_ob.o_outlet,ps_list,6,list); 00118 } 00119 00120 void *filedate_new(void) 00121 { 00122 t_filedate *x; 00123 00124 x = object_alloc(filedate_class); 00125 outlet_new((t_object *)x,0); 00126 return x; 00127 } 00128
Copyright © 2008, Cycling '74