CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2008
    Posts
    86

    No Of Bytes in the File

    Can anybody please tell me, any library function available in C to get the no of bytes in File.

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: No Of Bytes in the File

    You can seek to end of file using fseek and then use ftell.
    In Windows you can use the GetFileSize and GetFileSizeEx APIs
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  3. #3
    Join Date
    Feb 2005
    Posts
    2,160

    Re: No Of Bytes in the File

    There's also stat and fstat in the standard C library.

  4. #4
    Join Date
    Aug 2008
    Posts
    112

    Re: No Of Bytes in the File

    Quote Originally Posted by scorrpeio View Post
    Can anybody please tell me, any library function available in C to get the no of bytes in File.
    If you have MSDN help installed you will find IoDeviceControl relating to DISK_GEOMETRY is provided with a small piece of code that should be compiled and run just fine to produce what you intend to achieve. Otherwise please visit MSDN homepage for the source is also available out there.

    Regards.
    ~V
    hi,,,

  5. #5
    Join Date
    Nov 2008
    Location
    india
    Posts
    53

    Re: No Of Bytes in the File

    this function will give file size in the remote machine with little modification u can use it for local machine also
    FileSize (string sMachine, string Path, unsigned long &iSize)
    {
    HANDLE hFile = NULL; // the file handle

    BOOL bFlag; // a result holder

    __int64 liFileSize;

    QueryPerformanceCounter((LARGE_INTEGER*)&liFileSize);

    __int64 liFileSizeTot=0;

    char esc1[5]="\\\\";

    char esc2[3]="\\";

    char fullFilePath[MAX_PATH +1];

    sPstPath.replace (1,1,"$");

    strcpy (fullFilePath,esc1);

    strcat(fullFilePath,sMachine.c_str () );

    strcat(fullFilePath,esc2);

    strcat(fullFilePath,sPstPath.c_str ());

    try
    {

    hFile = CreateFile( fullFilePath,
    GENERIC_READ,
    FILE_SHARE_READ,
    NULL,
    OPEN_EXISTING,
    NULL,
    NULL);
    }
    catch(...)
    {



    }

    if(GetFileSizeEx(hFile, (LARGE_INTEGER*)&liFileSize))
    {
    iSize=liFileSize;

    }
    else
    {




    }
    bFlag = CloseHandle(hFile);

    if (!bFlag)
    {


    }

    return 0;
    }
    Last edited by lok.vikram; February 26th, 2009 at 09:29 AM.

  6. #6
    Join Date
    Dec 2008
    Posts
    86

    Re: No Of Bytes in the File

    Thank you for the help guys!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured