dkrause@orion.oac.uci.edu (Doug Krause) (10/23/89)
I'm using Turbo C 2.0 on a PC clone. My question: I'm using findfirst and findnext to read the disk directory. In the structure returned are two integers that tell the file date and file time. Is there a function to convert these numbers into something more useful like hh:mm? Douglas Krause One yuppie can ruin your whole day. ---------------------------------------------------------------------- University of California, Irvine Internet: dkrause@orion.oac.uci.edu Welcome to Irvine, Yuppieland USA BITNET: DJKrause@ucivmsa
few@quad1.quad.com (Frank Whaley) (10/24/89)
In article <3540@orion.cf.uci.edu> dkrause@orion.oac.uci.edu (Doug Krause) writes: >I'm using Turbo C 2.0 on a PC clone. My question: I'm using findfirst >and findnext to read the disk directory. In the structure returned are >two integers that tell the file date and file time. Is there a function >to convert these numbers into something more useful like hh:mm? Sure, sprintf()... assuming a filled-in struct ffblk F: sprintf(buf, "%02d/%02d/%02d %02d:%02d", (F.ff_fdate >> 5) & 0xf, F.ff_fdate & 0x1f, (F.ff_fdate >> 9) + 80, (F.ff_ftime >> 11) & 0x1f, (F.ff_ftime >> 5) & 0x3f); Of course, also assuming American date format :-) Another interesting (hidden) function is: extern long pascal __DOSTIMETOU(unsigned date, unsigned time); which takes a MS-DOS directory date/time and turns it into a Un*x-like time value. -- Frank Whaley Senior Development Engineer Quadratron Systems Incorporated few@quad1.quad.com uunet!ccicpg!quad1!few Water separates the people of the world; Wine unites them.
austin@bucsf.bu.edu (Austin Ziegler) (10/24/89)
>>>>> On 23 Oct 89 13:12:05 GMT, dkrause@orion.oac.uci.edu (Doug Krause) said:
Doug> I'm using Turbo C 2.0 on a PC clone. My question: I'm using findfirst
Doug> and findnext to read the disk directory. In the structure returned are
Doug> two integers that tell the file date and file time. Is there a function
Doug> to convert these numbers into something more useful like hh:mm?
I think that there are functions (packtime and unpacktime or something
like that) to do this. I don't have my compiler in front of me now, but go
into the help mode, Header files, Dir.H, and then go to findfirst or
find/next. If it is not in that help section, look under DOS.H. If you
would post the proper answer, I would appreciate it. (I program in Pascal
more often...)
Elminster, the Sage of Shadowdale (austin@bucsf.bu.edu)
700 Commonwealth Box 2094, Boston, MA 02215
Pascal Guru here, I want to be a C guru...
Bob.Stout@p6.f506.n106.z1.fidonet.org (Bob Stout) (10/25/89)
In an article of <23 Oct 89 13:12:05 GMT>, (Doug Krause) writes: >I'm using Turbo C 2.0 on a PC clone. My question: I'm using findfirst >and findnext to read the disk directory. In the structure returned are >two integers that tell the file date and file time. Is there a function >to convert these numbers into something more useful like hh:mm? ------------------------------- Cut here ------------------------------------ /* Sample file date and time display.*/ #include <stdio.h> #include <dos.h> struct DOS_TIME { unsigned int ss : 5; unsigned int mm : 6; unsigned int hh : 5; } ; #define dos_time(t) (*(struct DOS_TIME *)(&(t))) struct DOS_DATE { unsigned int da : 5; unsigned int mo : 4; unsigned int yr : 7; } ; #define dos_date(t) (*(struct DOS_DATE *)(&(t))) main(int argc, char *argv[]) { #ifdef __ZTC__ /* Zortech C/C++ */ struct FIND *ffblk; #else /* TC/MSC */ struct find_t *ffblk = (struct find_t)malloc(sizeof(struct find_t)); #endif if (2 > argc) { puts("\aUsage: SHOWDATE filename[.ext]"); exit(1); } #ifdef __ZTC__ if (!(ffblk = findfirst(argv[1], 0xff))) #elif defined(__TURBOC__) if (findfirst(argv[1], ffblk, 0xff) #else /* MSC/QC */ if (_dos_findfirst(argv[1], 0xff, ffblk) #endif { printf("\aCant find %s\n", argv[1]); exit(2); } printf("File date is %d-%d-%d\n", dos_date(ffblk->date).mo, dos_date(ffblk->date).da, (dos_date(ffblk->date).yr + 80) % 100); printf("File time is %d:%d:%d\n", dos_time(ffblk->time).hh, dos_time(ffblk->time).mm, dos_time(ffblk->time).ss); } ----------------------------------------------------------------------------- Please note that I don't have TC up on this machine, so the findfirst syntax is from memory. Finally, you can also use TC's getftime() function and/or its ftime structure, e.g. ------------------------------- Cut here ------------------------------------ union { struct ftime ftp; struct { unsigned time, date; } detail; } stamp; stamp.detail.time = time_from_findfirst; stamp.detail.date = date_from_findfirst; printf("%d-%d-%d %2d:%02d:%02d\n", stamp.ftp.ft_month, stamp.ftp.ft_day, stamp.ftp.ft_year + 80, stamp.ftp.ft_hour, stamp.ftp.ft_min, stamp.ftp.ft_tsec * 2); ----------------------------------------------------------------------------- Of course all this is highly non-portable, but then it *is* OS-specific...