Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

bepo

Frischling

  • »bepo« ist der Autor dieses Themas

Beiträge: 33

Wohnort: Bayern

Beruf: Schüler

  • Private Nachricht senden

1

23.09.2004, 15:50

Dateigröße abfragen?

Wie kann man die Größe einer Datei abfragen?

2

23.09.2004, 15:58

Mit _stat.

Patrick

Alter Hase

Beiträge: 1 264

Wohnort: Düren

Beruf: Fachinformatiker für Anwendungsentwicklung

  • Private Nachricht senden

3

23.09.2004, 18:09

Hi,

MSDN spuckt das aus :)

Zitat

GetFileSize
The GetFileSize function retrieves the size of a specified file.

This function stores the file size in a DWORD value. To retrieve a file size that is larger than a DWORD value, use the GetFileSizeEx function.

C-/C++-Quelltext

1
2
3
4
DWORD GetFileSize(
  HANDLE hFile,           // handle to file

  LPDWORD lpFileSizeHigh  // high-order word of file size

);

Parameters
hFile
[in] Handle to the file whose size is to be returned. This handle must have been created with either GENERIC_READ or GENERIC_WRITE access to the file.
lpFileSizeHigh
[out] Pointer to the variable where the high-order word of the file size is returned. This parameter can be NULL if the application does not require the high-order word.
Return Values
If the function succeeds, the return value is the low-order doubleword of the file size, and, if lpFileSizeHigh is non-NULL, the function puts the high-order doubleword of the file size into the variable pointed to by that parameter.

If the function fails and lpFileSizeHigh is NULL, the return value is INVALID_FILE_SIZE. To get extended error information, call GetLastError.

If the function fails and lpFileSizeHigh is non-NULL, the return value is INVALID_FILE_SIZE and GetLastError will return a value other than NO_ERROR.

Remarks
You cannot use the GetFileSize function with a handle of a nonseeking device such as a pipe or a communications device. To determine the file type for hFile, use the GetFileType function.

The GetFileSize function retrieves the uncompressed size of a file. Use the GetCompressedFileSize function to obtain the compressed size of a file.

Example Code
Note that if the return value is INVALID_FILE_SIZE and lpFileSizeHigh is non-NULL, an application must call GetLastError to determine whether the function has succeeded or failed. The following sample code illustrates this point:

C-/C++-Quelltext

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
// Case One: calling the function with 

//           lpFileSizeHigh == NULL 

 
// Try to obtain hFile's size 

dwSize = GetFileSize (hFile, NULL) ; 
 
// If we failed ... 

if (dwSize == INVALID_FILE_SIZE) 
{ 
    // Obtain the error code. 

    dwError = GetLastError() ; 
 
    // Deal with that failure. 

    . 
    . 
    . 
 
    } // End of error handler 

 
 
// 

// Case Two: calling the function with 

//           lpFileSizeHigh != NULL 

 
// Try to obtain hFile's huge size. 

dwSizeLow = GetFileSize (hFile, & dwSizeHigh) ; 
 
// If we failed ... 

if (dwSizeLow == INVALID_FILE_SIZE 
    && 
    (dwError = GetLastError()) != NO_ERROR )
{ 
    // Deal with that failure. 

    . 
    . 
    . 
 
    } // End of error handler.

For another example, see Two Examples of File Mapping.

Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.

See Also
File I/O Overview, File I/O Functions, GetCompressedFileSize, GetFileSizeEx, GetFileType

Platform SDK Release: August 2001 What did you think of this topic?
Let us know. Order a Platform SDK CD Online
(U.S/Canada) (International)



- Patrick :)

4

23.09.2004, 19:22

Warum mach ich alles falsch? :crying:
Erst da
https://www.spieleprogrammierer.de/index…iewtopic&t=2479
und jetzt hier. :crying: :crying: :crying:

Patrick

Alter Hase

Beiträge: 1 264

Wohnort: Düren

Beruf: Fachinformatiker für Anwendungsentwicklung

  • Private Nachricht senden

5

23.09.2004, 19:34

Na na na! Wer wird denn da gleich weinen? :)

Learning By Doing und bissel searching in den FAQs wirken sehr oft :)

- Patrick

p.s.: Niemals unterkriegen lassen ;)

6

23.09.2004, 19:46

Halt ne Pechsträne :D

7

25.09.2004, 15:17

Wer auf WinAPI verzichten will und nur die STL nutzen will kann es auch so machen

C-/C++-Quelltext

1
2
3
4
std::ifstream fin("text.txt");

fin.seekg(0, std::ios::end);
size_t size = fin.tellg();
Wichtig! Ich übernehme keinerlei Verantwortung für eventl. Datenverlust oder Schäden am Rechner ;D

Werbeanzeige