-
February 26th, 2009, 01:14 AM
#1
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.
-
February 26th, 2009, 01:21 AM
#2
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
-
February 26th, 2009, 09:16 AM
#3
Re: No Of Bytes in the File
There's also stat and fstat in the standard C library.
-
February 26th, 2009, 09:20 AM
#4
Re: No Of Bytes in the File
Originally Posted by scorrpeio
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,,,
-
February 26th, 2009, 09:27 AM
#5
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.
-
February 27th, 2009, 12:23 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|