1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| #include <dir.h>
#include <stdio.h>
#pragma warn -par
void main(int argc,char *argv[])
{
struct ffblk f;
int done;
long totfiles=0L,totsize=0L;
done=findfirst("*.*",&f,0x3f);
while(!done) {
printf("%s %ld",f.ff_name,f.ff_fsize);
if(*f.ff_name=='.') printf(" dir");
printf("\x0d\x0a");
totfiles++; totsize+=f.ff_fsize;
done=findnext(&f);
}
findclose(&f);
printf("%ld fichiers, %ld bytes\n",totfiles,totsize);
}
#pragma warn .par
/* ----------------------------------------------------------------------------
Dans dir.h (Borland C++builder6), on trouve:
struct ffblk {
long ff_reserved;
long ff_fsize;
unsigned long ff_attrib;
unsigned short ff_ftime;
unsigned short ff_fdate;
char ff_name[MAXPATH];
};
int _RTLENTRYF _EXPFUNC findfirst( const char _FAR *__path,
struct ffblk _FAR *__ffblk,
int __attrib );
int _RTLENTRYF _EXPFUNC findnext( struct ffblk _FAR *__ffblk );
int _RTLENTRYF _EXPFUNC findclose( struct ffblk _FAR *__ffblk );
---------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------
Résultats compilation & link: (effectués sous dos)
C:\Program Files\Borland\CBuilder6\src>bcc32 -WCR -K mydir.c
Borland C++ 5.6 for Win32 Copyright (c) 1993, 2002 Borland
mydir.C:
Turbo Incremental Link 5.60 Copyright (c) 1997-2002 Borland
---------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------
Sortie écran du programme: (effectués sous dos)
65535 -->parfois aussi 0
1 fichiers, 65535 bytes
---------------------------------------------------------------------------- */ |
Partager