Thread: files size to char[]

  1. #1
    Registered User
    Join Date
    Apr 2005
    Costa Rica

    Question storing of files size to char[]

    well I am under XP using VC++6.
    So, I need to get the file size of a bunch of files into char[].
    //Declaration of token:
    char *token[512] = {0};
    later token holds all the file names I need.
    The way for getting a file's size I use is:

    GetFileAttributesEx(TEXT("File.txt"), GetFileExInfoStandard, &wfad);
    printf("Size of File.txt is %u\n", wfad.nFileSizeHigh);
    but using a for loop doesnt work, it shows the very same value for every token[i].
    so if I use:
    //say the number of files is 16
    for (int J=0;J<=15;J++)
    GetFileAttributesEx(TEXT(token[J]), GetFileExInfoStandard, &wfad);
    printf("Size-> %u\n", wfad.nFileSizeHigh);
    it will show the same number for all the token[J].
    how can I store the file sizes in token[] to a char[]??? (lets name it FileSizes[])

    also if anyone knows what is nFileSizeHigh and nFileSizeLow that would hel me understand better what's going on.

    thanks a lot! =D
    Last edited by purefan; 04-03-2005 at 07:41 PM. Reason: claryfing the Title

  2. #2
    Registered User
    Join Date
    Apr 2003
    hello! well I am under XP using VC++6.
    also if anyone knows what is nFileSizeHigh and nFileSizeLow that would hel me understand better what's going on.
    Well, in VC++6, if you click on Help>Index and paste in: WIN32_FILE_ATTRIBUTE_DATA, hit return, and insert the required MSDN disc, you will be presented with this information:
    The WIN32_FILE_ATTRIBUTE_DATA structure contains attribute information for a file or directory. The GetFileAttributesEx function uses this structure.
    typedef struct _WIN32_FILE_ATTRIBUTE_DATA{ 
        DWORD      dwFileAttributes; 
        FILETIME   ftCreationTime; 
        FILETIME   ftLastAccessTime; 
        FILETIME   ftLastWriteTime; 
        DWORD      nFileSizeHigh; 
        DWORD      nFileSizeLow; 
    Specifies the high-order DWORD of the file size. This member has no meaning for directories.
    Specifies the low-order DWORD of the file size. This member has no meaning for directories.
    Pasting DWORD into the index, turns up this:
    DWORD 32-bit unsigned integer.
    Here is a description of the function you are calling:
    The GetFileAttributesEx function obtains attribute information about a specified file or directory.
    BOOL GetFileAttributesEx(
      LPCTSTR lpFileName,       // file or directory name
      GET_FILEEX_INFO_LEVELS fInfoLevelId,  // attributes 
      LPVOID lpFileInformation   // receives attributes 
    Pointer to a null-terminated string that specifies a file or directory.
    By default, this string is limited to MAX_PATH characters. The limit is related to how the GetFileAttributesEx function parses paths. An application can transcend this limit and send in paths longer than MAX_PATH characters by calling the wide (W) version of GetFileAttributesEx and prepending "\\?\" to the path. However, each component in the path cannot be more than MAX_PATH characters long. The "\\?\" tells the function to turn off path parsing. This technique also works with UNC names. The "\\?\" is ignored as part of the path. For example, "\\?\C:\myworld\private" is seen as "C:\myworld\private", and "\\?\UNC\peanuts\hotstuff\coolapps" is seen as "\\peanuts\hotstuff\coolapps".

    Specifies a GET_FILEEX_INFO_LEVELS enumeration type that gives the set of attribute information to obtain.
    Pointer to a buffer that receives the attribute information. The type of attribute information stored into this buffer is determined by the value of fInfoLevelId.
    Return Values
    If the function succeeds, the return value is a nonzero value.

    If the function fails, the return value is zero. To get extended error information, call GetLastError.
    LPVOID Generic pointer type, equivalent to (void *). Should be used instead of LPSTR.
    I don't see a DWORD parameter for that function, so why are you using nFileSizeHigh?
    Last edited by 7stud; 04-03-2005 at 09:01 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. I Need To Know Some Things That I Can Put Into A Batch File
    By TheRealNapster in forum A Brief History of
    Replies: 1
    Last Post: 10-20-2003, 08:12 PM
  3. Makefiles, Object files, Source files, OH MY!
    By Inquirer in forum Linux Programming
    Replies: 2
    Last Post: 04-29-2003, 10:36 PM
  4. Replies: 11
    Last Post: 03-25-2003, 05:13 PM
  5. Size of exe files
    By Korn1699 in forum C++ Programming
    Replies: 6
    Last Post: 03-25-2002, 09:46 PM