From Bob Stout · 1996-04-01 14:39 · #73523 in EMULATE
In reply to ff_fdate question by Kyle Hellewell
In a message of <Mar 31 20:37>, Kyle Hellewell (1:246/12.1@fidonet) writes:
>I'm trying to get file dates out of ffblk.ff_fdate using findfirst and
>findnext, but the numbers that it gives me are four digit numbers that I
>can't seem to decipher using the information that they give me in help.
>Can anyone tell me what I have to do to turn this into a normal date
>code? FYI, it says in help that these codes that it's giving me are
>16-bit, and are stored the same way that dos stores its file dates (How
>can a 4 digit # be 16 bits?)
Kyle...
Obviously, you're working with a Borland compiler. Here's Borland-specific code. For a more portable solution, look up DIRPORT.H in SNIPPETS, which is demonstrated in the SNIPPETS file LSD.C - a DOS DIR work-alike.
#include <stdio.h>
#include <dir.h>
struct DOS_TIME
{
unsigned int ss : 5;
unsigned int mm : 6;
unsigned int hh : 5;
} ;
struct DOS_DATE
{
unsigned int da : 5;
unsigned int mo : 4;
unsigned int yr : 7;
} ;
#define dos_time(t) (*(struct DOS_TIME *)(&(t)))
#define dos_date(t) (*(struct DOS_DATE *)(&(t)))
main(int argc, char *argv[])
{
struct ffblk ff;
if (2 > argc)
{
puts("\aUsage: SHOWDATE filename[.ext]");
return 1;
}
if (0 != findfirst(argv[1], &ff, 0xff))
{
printf("\aCant find %s\n", argv[1]);
return 2;
}
printf("File date is %d-%d-%d\n",
dos_date(ff.ff_fdate).mo,
dos_date(ff.ff_fdate).da,
(dos_date(ff.ff_fdate).yr + 80) % 100);
printf("File time is %d:%d:%d\n",
dos_time(ff.ff_ftime).hh,
dos_time(ff.ff_ftime).mm,
dos_time(ff.ff_ftime).ss * 2);
return 0;
}
--- QM v1.00
* Origin: MicroFirm : Down to the C in chips (1:106/2000.6)