Example |
U16 ftp_ffind (U8 code, U8 *buf, U8 *mask, U16 len) {
/* Find file names and other file information. */
static FINFO info;
U32 rlen,v;
U8 *tp;
if (code < 4) {
/* First call to ffind, initialize the info. */
info.fileID = 0;
}
rlen = 0;
next:
if (ffind ((char *)mask, &info) == 0) {
/* File found, print file information. */
if (info.name[0] == '.') {
if ((info.name[1] == 0) || (info.name[1] == '.' && info.name[2]) == 0) {
/* Ignore the '.' and '..' folders. */
goto next;
}
}
switch (code) {
case 0:
/* Return file size as decimal number. */
rlen = sprintf ((char *)buf,"%d\r\n", info.size);
break;
case 1:
/* Return last-modified time in format "YYYYMMDDhhmmss". */
rlen = sprintf ((char *)buf,"%04d%02d%02d",
info.time.year, info.time.mon, info.time.day);
rlen += sprintf ((char *)&buf[rlen],"%02d%02d%02d\r\n",
info.time.hr, info.time.min, info.time.sec);
break;
case 2:
case 4:
/* List file names only. */
rlen = sprintf ((char *)buf,"%s\r\n", info.name);
break;
case 3:
case 5:
/* List directory in extended format. */
rlen = sprintf ((char *)buf,"%02d-%02d-%02d",
info.time.mon, info.time.day, info.time.year%100);
/* Convert time to "AM/PM" format. */
v = info.time.hr % 12;
if (v == 0) v = 12;
if (info.time.hr < 12) tp = "AM";
else tp = "PM";
rlen += sprintf ((char *)&buf[rlen]," %02d:%02d%s",v,info.time.min,tp);
if (info.attrib & ATTR_DIRECTORY) {
rlen += sprintf ((char *)&buf[rlen],"%-21s"," <DIR>");
}
else {
rlen += sprintf ((char *)&buf[rlen],"%21d", info.size);
}
rlen += sprintf ((char *)&buf[rlen]," %s\r\n", info.name);
break;
}
}
return (rlen);
}
|