CPB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Directory Date ?? And comparing dates



I ran into this and used the standard c++ findfirst and findnext and had 
to create a bit structure and a union to take the ff_fdate apart.
The following snippits may help you.

struct bits
{
    unsigned int day   : 5;
    unsigned int month : 4;
    unsigned int year  : 7;
    unsigned int extra : 1;
}mdate;

union
{
    unsigned int   udate;
    struct   bits  mdate; 
}DU;

I created an array of ffblk[] and filled it with the file structures 
from the findfirst findnext functions.

I then sorted the array elements with qsort(ffblk,array_element_count,
sizeof(single_element),CompareDates);

int CompareDates(const void* d1, const void* d2)
{
    ffblk *f,*l;
    f = (ffblk*)d1;
    l = (ffblk*)d2;
    return (f->ff_date - l->ffdate);
}

//then to print them
for(int i = 0; i<elementcount;i++)
{
    DU.udate = yoursortedstructarray[i].ff_fdate;
    sprintf(buffer,"%s\t%02d/%02d/%d", yourarray[i].ff_name,
	    DU.mdate.month,DU.mdate.day,DU.mdate.year+1980);
    cout<<buffer<<endl;
}
There must be an easier way.
Mike


W Komornicki's Home Page | Main Index | Thread Index