May 9, 2009 at 5:54pm UTC
I need to write a dll which include a function that return file size
would any one help me to finish the part between /*** and **/
/***
bool Check_file_size ()
{
int Size_1 = GetSize("myself.dll") ;
int Size_2 = GetSize("upper_folder\serial.txt") ;
int Size_3 = GetSize("upper_folder\happy.fcv") ;
if (Szie_1 != default_1 ) return(false);
if (Size_2 != default_2 ) return(false);
if (Size_3 != default_3 ) return(false);
}
int Get_Size(string path);
{
....
....
return(Size);
}
**/
let's give an example of what upper_folder means
as above mentioned, there is a "myself.dll" in C:\Programs File\Success\libraries\
then the "serial.txt" and "happy.fcv" is in C:\Programs File\Success\
I am a beginner of programming ^^
big thanks
Last edited on Jun 11, 2009 at 9:26am UTC
May 9, 2009 at 6:53pm UTC
fopen();
fseek(seek to the end of the file)
ftell(get the file size in bytes)
fseek(again come to the begining of the file if you want to traverse the file)
May 10, 2009 at 12:03pm UTC
Windows/*NIX (and probably most conventional OS') support stat
function.
May 10, 2009 at 2:12pm UTC
hehehehe... me too... :P
infact replied to someone about stat...
Jun 11, 2009 at 9:28am UTC
i have find the answer on internet already
handle=FileOpen("filename", FILE_CSV|FILE_WRITE, ';');
if(handle>0)
{
FileWrite(handle, Close[0], Open[0], High[0], Low[0], TimeToStr(orderOpen));
FileClose(handle);
}
i don't know what is handle before..
Last edited on Jun 11, 2009 at 9:29am UTC
Jun 13, 2009 at 10:57pm UTC
if a file is reading by another process, and i want to get the size of this file, which is better for getting it's size? GetFileSize or Ftell ?
Jun 17, 2009 at 7:35pm UTC
int Get_Size( string path )
{
// #include <fstream>
FILE *pFile = NULL;
// get the file stream
fopen_s( &pFile, path.c_str(), "rb" );
// set the file pointer to end of file
fseek( pFile, 0, SEEK_END );
// get the file size
int Size = ftell( pFile );
// return the file pointer to begin of file if you want to read it
// rewind( pFile );
// close stream and release buffer
fclose( pFile );
return Size;
}
Jun 17, 2009 at 7:59pm UTC
It would be better to use off_t (or loff_t) than int.
Jun 18, 2009 at 1:58am UTC
off_t (or loff_t) than int.
off_t Size = ftell( pFile );
right?