473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

File Size

57
How Can I Print The File Size In Console??????(in Bytes)
Jun 29 '06 #1
10 32671
Banfa
9,065 Expert Mod 8TB
I don't quite understand how what you are asking this time is different from the discussion you started in this thread

http://www.thescripts.com/forum/thread506204.html
Jun 29 '06 #2
Finding the size of the file in C/C++ can be done easily.

Create a file pointer for the input file.
Read character by character and count the characters in a variable.
The total no. of characters in count gives the size of the file in bytes.

Try it.
Jun 29 '06 #3
Banfa
9,065 Expert Mod 8TB
Finding the size of the file in C/C++ can be done easily.

Create a file pointer for the input file.
Read character by character and count the characters in a variable.
The total no. of characters in count gives the size of the file in bytes.
That's a rather long winded method when you can open a file,jump to the end of it and the read the current file pointer position (i.e. the file size) without having to read every character and keep your own count.

I suggest you look at the other thread I have linked to in my first reply.
Jun 29 '06 #4
Kasya
57
Thanks!!!!!!! But I don't Understand One Thing:

If Files Characters are 10400 Will The File Be 10400 bytes??????
Jun 30 '06 #5
Banfa
9,065 Expert Mod 8TB
Well that rather depends, if you used kuttalambala method and you opened the file in text then the number of characters wont neccessarily be the number of bytes because end of line processing happens which means that the character sequence in the file "\r\n" (carridge return newline) is returned to the program as "\n" so every time there is a new line in the file you count 1 less characters than actually exist in it (for a file with DOS/Windows end of lines).

However ignoring that then basically file byte size and number of characters in the file are basically the same.
Jun 30 '06 #6
Kasya
57
Thanks!!!!
Jun 30 '06 #7
Why not stick to the old faithful ? :

Expand|Select|Wrap|Line Numbers
  1. long FileSize(char* filename)
  2. {
  3.   struct stat stbuf;
  4.   stat(filename, &stbuf);
  5.   return stbuf.st_size;
  6. }
That's the method described in "The C Programming Language" is much simpler than any other technique, plus you get access to all this as well:

Expand|Select|Wrap|Line Numbers
  1. struct stat   /* inode information returned by stat */
  2.    {
  3.        dev_t     st_dev;      /* device of inode */
  4.        ino_t     st_ino;      /* inode number */
  5.        short     st_mode;     /* mode bits */
  6.        short     st_nlink;    /* number of links to file */
  7.        short     st_uid;      /* owners user id */
  8.        short     st_gid;      /* owners group id */
  9.        dev_t     st_rdev;     /* for special files */
  10.        off_t     st_size;     /* file size in characters */
  11.        time_t    st_atime;    /* time last accessed */
  12.        time_t    st_mtime;    /* time last modified */
  13.        time_t    st_ctime;    /* time originally created */
  14.    };
  15.  
Aug 20 '07 #8
weaknessforcats
9,208 Expert Mod 8TB
Why not stick to the old faithful ? :
It's not portable. Only works for Unix.
Aug 20 '07 #9
lini
12
cross-platform:

Expand|Select|Wrap|Line Numbers
  1.   ifstream is;
  2.   is.open ("test.txt", ios::binary );
  3.  
  4.   // get length of file:
  5.   is.seekg (0, ios::end);
cheers,
lini
Nov 5 '08 #10
donbock
2,426 Expert 2GB
That's fine, as long as you remember that stat() isn't part of the Standard C Library so it may not be fully portable. However, stat is part of IEEE Std 1003.1 (POSIX) so it should be available in at least all versions of unix.
Nov 5 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Joe | last post by:
Hello, I have IIS 6.0 running on w2k3 Enterprise. I have three upload forms 1 to have restricted uploads .asp 2 to upload plain .asp any extension 3 a FP form upload non .asp
17
by: Arnold | last post by:
Is using fseek and ftell a reliable method of getting the file size on a binary file? I thought I remember reading somewhere it wasn't... If not what would be the "right" and portable method to...
6
by: Andrew Clark | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** Hello all, I recall several threads over the years about how reading file size cannot be done consistantly or portably, but I...
49
by: Sam | last post by:
Hi all, Is there a function in the standard library that can get the size of a file? Thank you very much. Sam.
5
by: Claudio Grondi | last post by:
I have just started to play around with the bsddb3 module interfacing the Berkeley Database. Beside the intended database file databaseFile.bdb I see in same directory also the __db.001...
11
by: Parrot | last post by:
Is there any routine I can call to reduce the size of an image file after uploading a file from a client. I am looking to reduce file sizes programmatically using C# in my web page after uploading....
5
by: Jefferis NoSpamme | last post by:
Hi all, I'm trying to limit the file size of an image submission and I keep running into various problems. I've got most of it working, but I'm stumped and I have a basic question as to WHY this...
7
by: Adrián E. Córdoba | last post by:
Hi, there! I'm developing a little application which must record some events in a log file (.txt). How can I delete the first line in the log file every time I add a new line at the end, in order...
4
by: Doug | last post by:
Hi, It looks like the only way to get a size of a file within csharp is to use FileInfo and the Length property. However that only returns the number of bytes in the file which is translating...
1
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.