Path: utzoo!dciem!nrcaer!cognos!brianc From: brianc@cognos.uucp (Brian Campbell) Newsgroups: comp.lang.c Subject: Re: Turbo C Date Conversion Message-ID: <2242@cognos.UUCP> Date: 8 Feb 88 17:08:11 GMT Article-I.D.: cognos.2242 Posted: Mon Feb 8 12:08:11 1988 References: <454@picuxa.UUCP> Reply-To: brianc@cognos.UUCP (Brian Campbell) Organization: Cognos Incorporated, Ottawa, Canada Lines: 55 In article <454@picuxa.UUCP> rcr@picuxa.UUCP (Richard Court ) writes: > I am writing a program to list directory attributes. I am using the > "findfirst" and "findnext" routines to extract file information for me > and then "strcpy" data out of the "ffblk" structure to fill my arrays. > > What I can't figure out is how to convert the file date and time. They > are placed in the ffblk structure as packed integers and I'll be damned > if I can figure out a way to get them into strings! The following program will list the contents of the current directory, formatting the date as yy-mm-dd, and the time as hh:mm:ss. It should make DOS' date and time packing obvious. P.S. The structs defined work under Turbo C 1.5, under other compilers (and/or versions of Turbo C) it may be necessary to reverse the order of the fields. #include #include #include struct dosdate { unsigned day : 5; unsigned month : 4; unsigned year : 7; }; struct dostime { unsigned bisecond : 5; unsigned minute : 6; unsigned hour : 5; }; main() { struct ffblk ff; if (findfirst("*.*", &ff, 0) != 0) { printf("No files found\n"); exit(1); } do { printf("%14s %2d-%02d-%02d %2d:%02d:%02d\n", ff.ff_name, ((struct dosdate *) &ff.ff_fdate)->year + 80, ((struct dosdate *) &ff.ff_fdate)->month, ((struct dosdate *) &ff.ff_fdate)->day, ((struct dostime *) &ff.ff_ftime)->hour, ((struct dostime *) &ff.ff_ftime)->minute, ((struct dostime *) &ff.ff_ftime)->bisecond * 2); } while (findnext(&ff) == 0); } -- Brian Campbell uucp: decvax!utzoo!dciem!nrcaer!cognos!brianc Cognos Incorporated mail: POB 9707, 3755 Riverside Drive, Ottawa, K1G 3Z4 (613) 738-1440 fido: (613) 731-2945 300/1200, sysop@1:163/8