Finding file’s size

Try this; NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:URL error:&attributesError]; NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize]; long long fileSize = [fileSizeNumber longLongValue]; Note that the fileSize won’t necessarily fit in an integer (especially a signed one) although you could certainly drop to a long for iOS as you’ll never exceed that in reality. The example uses long … Read more

smallest filesize for transparent single pixel image

First of all, there is honestly no valid reason to use spacer GIFs in 2020 and beyond (unless you’re working with retro style websites), so this post is mostly just for the curious. Anyway let’s begin: The smallest valid transparent GIF is 35 bytes. data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEAAAAALAAAAAABAAEAAAIBAAA= 47 49 46 38 39 61 01 00 01 00 … Read more

File-size format provider

I use this one, I get it from the web public class FileSizeFormatProvider : IFormatProvider, ICustomFormatter { public object GetFormat(Type formatType) { if (formatType == typeof(ICustomFormatter)) return this; return null; } private const string fileSizeFormat = “fs”; private const Decimal OneKiloByte = 1024M; private const Decimal OneMegaByte = OneKiloByte * 1024M; private const Decimal OneGigaByte … Read more

Size of an open file object

$ ls -la chardet-1.0.1.tgz -rwxr-xr-x 1 vinko vinko 179218 2008-10-20 17:49 chardet-1.0.1.tgz $ python Python 2.5.1 (r251:54863, Jul 31 2008, 22:53:39) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 Type “help”, “copyright”, “credits” or “license” for more information. >>> f = open(‘chardet-1.0.1.tgz’,’rb’) >>> f.seek(0, os.SEEK_END) >>> f.tell() 179218L Adding ChrisJY’s idea to the example >>> import os … Read more

Get size of file on disk

This uses GetCompressedFileSize, as ho1 suggested, as well as GetDiskFreeSpace, as PaulStack suggested, it does, however, use P/Invoke. I have tested it only for compressed files, and I suspect it does not work for fragmented files. public static long GetFileSizeOnDisk(string file) { FileInfo info = new FileInfo(file); uint dummy, sectorsPerCluster, bytesPerSector; int result = GetDiskFreeSpaceW(info.Directory.Root.FullName, … Read more

How to get remote file size from a shell script?

You can download the file and get its size. But we can do better. Use curl to get only the response header using the -I option. In the response header look for Content-Length: which will be followed by the size of the file in bytes. $ URL=”http://api.twitter.com/1/statuses/public_timeline.json” $ curl -sI $URL | grep -i Content-Length … Read more