Zum Inhalt springen

datum der datei auslesen


Poldi

Empfohlene Beiträge

>>Mit MFC:

CFile::GetStatus

BOOL GetStatus( CFileStatus& rStatus ) const;

static BOOL PASCAL GetStatus( LPCTSTR lpszFileName, CFileStatus& rStatus );

Return Value

TRUE if the status information for the specified file is successfully obtained; otherwise, FALSE.

Parameters

rStatus

A reference to a user-supplied CFileStatus structure that will receive the status information. The CFileStatus structure has the following fields:

CTime m_ctime The date and time the file was created.

CTime m_mtime The date and time the file was last modified.

CTime m_atime The date and time the file was last accessed for reading.

LONG m_size The logical size of the file in bytes, as reported by the DIR command.

BYTE m_attribute The attribute byte of the file.

char m_szFullName[_MAX_PATH] The absolute filename in the Windows character set.

lpszFileName

A string in the Windows character set that is the path to the desired file. The path can be relative or absolute, but cannot contain a network name.

Remarks

The virtual version of GetStatus retrieves the status of the open file associated with this CFile object. It does not insert a value into the m_szFullName structure member.

The static version gets the status of the named file and copies the filename to m_szFullName. This function obtains the file status from the directory entry without actually opening the file. It is useful for testing the existence and access rights of a file.

The m_attribute is the file attribute. The Microsoft Foundation classes provide an enum type attribute so that you can specify attributes symbolically:

enum Attribute {

normal = 0x00,

readOnly = 0x01,

hidden = 0x02,

system = 0x04,

volume = 0x08,

directory = 0x10,

archive = 0x20

};

Example

//example for CFile::GetStatus

CFileStatus status;

extern CFile cfile;

if( cfile.GetStatus( status ) ) // virtual member function

{

#ifdef _DEBUG

afxDump << "File size = " << status.m_size << "\n";

#endif

}

char* pFileName = "test.dat";

if( CFile::GetStatus( pFileName, status ) ) // static function

{

#ifdef _DEBUG

afxDump << "Full file name = " << status.m_szFullName << "\n";

#endif

}

>>Oder ohne MFC:

fstat, _fstati64

Get information about an open file.

int _fstat( int handle, struct _stat *buffer );

__int64 _fstati64( int handle, struct _stat *buffer );

Function Required Header Compatibility

_fstat <sys/stat.h> and <sys/types.h> Win 95, Win NT

_fstati64 <sys/stat.h> and <sys/types.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version

LIBCMT.LIB Multithread static library, retail version

MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

_fstat and _fstati64 return 0 if the file-status information is obtained. A return value of –1 indicates an error, in which case errno is set to EBADF, indicating an invalid file handle.

Parameters

handle

Handle of open file

buffer

Pointer to structure to store results

Remarks

The _fstat function obtains information about the open file associated with handle and stores it in the structure pointed to by buffer. The _stat structure, defined in SYS\STAT.H, contains the following fields:

st_atime

Time of last file access.

st_ctime

Time of creation of file.

st_dev

If a device, handle; otherwise 0.

st_mode

Bit mask for file-mode information. The _S_IFCHR bit is set if handle refers to a device. The _S_IFREG bit is set if handle refers to an ordinary file. The read/write bits are set according to the file‚s permission mode. _S_IFCHR and other constants are defined in SYS\STAT.H.

st_mtime

Time of last modification of file.

st_nlink

Always 1 on non-NTFS file systems.

st_rdev

If a device, handle; otherwise 0.

st_size

Size of the file in bytes.

If handle refers to a device, the st_atime, st_ctime, and st_mtime and st_size fields are not meaningful.

Because STAT.H uses the _dev_t type, which is defined in TYPES.H, you must include TYPES.H before STAT.H in your code.

Example

/* FSTAT.C: This program uses _fstat to report

* the size of a file named F_STAT.OUT.

*/

#include <io.h>

#include <fcntl.h>

#include <time.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

void main( void )

{

struct _stat buf;

int fh, result;

char buffer[] = "A line to output";

if( (fh = _open( "f_stat.out", _O_CREAT | _O_WRONLY |

_O_TRUNC )) == -1 )

_write( fh, buffer, strlen( buffer ) );

/* Get data associated with "fh": */

result = _fstat( fh, &buf );

/* Check if statistics are valid: */

if( result != 0 )

printf( "Bad file handle\n" );

else

{

printf( "File size : %ld\n", buf.st_size );

printf( "Time modified : %s", ctime( &buf.st_ctime ) );

}

_close( fh );

}

Output

File size : 0

Time modified : Tue Mar 21 15:23:08 1995

<FONT COLOR="#a62a2a" SIZE="1">[ 06. Dezember 2001 12:05: Beitrag 1 mal editiert, zuletzt von Crush ]</font>

Link zu diesem Kommentar
Auf anderen Seiten teilen

Die 2. Version sollte auch theoretisch unter Unix laufen weil das das Standard-File-Handling ist. (teste mal das Beispiel aus, arbeite aber mit fopen vom stdio.h anstatt _Open() und dasselbe mit fclose() anstatt _Close(), weil ich nicht weiß ob das die M$-Leutz aus Bequemlichkeit selber definiert haben.

<FONT COLOR="#a62a2a" SIZE="1">[ 06. Dezember 2001 13:41: Beitrag 3 mal editiert, zuletzt von Crush ]</font>

Link zu diesem Kommentar
Auf anderen Seiten teilen

Dein Kommentar

Du kannst jetzt schreiben und Dich später registrieren. Wenn Du ein Konto hast, melde Dich jetzt an, um unter Deinem Benutzernamen zu schreiben.

Gast
Auf dieses Thema antworten...

×   Du hast formatierten Text eingefügt.   Formatierung wiederherstellen

  Nur 75 Emojis sind erlaubt.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Editor leeren

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...