Python Check if File Exists: pathlib, os.path and Safe Patterns
Path("x").is_file() checks for a file, is_dir() for a folder and exists() for either. Plus create-if-missing, delete-if-present, wildcards, empty files and race conditions.
A drive sold as 1TB shows as about 931GB in Windows because the two use different units.
A drive sold as 1TB shows as about 931GB in Windows because the two use different units. Drive makers count 1TB as 1,000,000,000,000 bytes (powers of 1,000). Windows divides by powers of 1,024 and still labels the result "GB", when it is really gibibytes (GiB). No space has gone missing; the same number of bytes is being described two ways. A small extra amount also goes to partitions and the file system.
Below you will find the maths, a table for common drive sizes, and how to check your own drive. For quick conversions, use the GB to TB converter.
Contents
Computers work in binary, so early software measured memory in powers of 2. A "kilobyte" came to mean 1,024 bytes because 2 to the power of 10 is 1,024, which is close to 1,000. The gap is small at that size but grows with each step.
To end the confusion, the International Electrotechnical Commission created binary prefixes in 1998: kibibyte (KiB), mebibyte (MiB), gibibyte (GiB) and tebibyte (TiB). The US National Institute of Standards and Technology explains these prefixes. Drive makers use the standard SI meaning, so 1GB is 1,000,000,000 bytes.
Decimal (SI)BytesBinary (IEC)Bytes1 KB1,0001 KiB1,0241 MB1,000,0001 MiB1,048,5761 GB1,000,000,0001 GiB1,073,741,8241 TB1,000,000,000,0001 TiB1,099,511,627,776Take a 1TB drive with 1,000,000,000,000 bytes. Windows divides by 1,024 three times to get "GB":
1,000,000,000,000 ÷ 1,073,741,824 = 931.32
So Windows reports about 931GB. The difference is roughly 6.9% at the terabyte level, and it grows to about 9.1% at the tebibyte level for larger drives.
Real drives often hold slightly more bytes than the round number, so your figure may be a little higher than this table.
No. Since Mac OS X 10.6 Snow Leopard, macOS reports storage in decimal units, so a 1TB drive shows as about 1TB. Windows is the main system that still divides by 1,024 while labelling the result GB. Phones vary by maker, and the operating system itself takes a large share of internal storage.
If the byte count is far below the label, for example a "1TB" USB stick showing 32GB worth of bytes, the drive may be fake. Test it before you trust it with data. For other conversions, the bytes to MB converter gives exact values.
Drive makers count 1TB as one trillion bytes. Windows divides by 1,024 instead of 1,000 and labels the result GB, so the same space appears as about 931GB.
Under the SI standard, 1GB is 1,000MB. The binary unit, 1GiB, is 1,024MiB. Windows uses the binary value but writes GB.
A gibibyte is 1,073,741,824 bytes (1,024 to the power of 3). It was defined by the IEC to separate binary sizes from decimal ones.
No. The maker labels capacity in standard decimal units, and the bytes are all there. The difference comes from how Windows displays the number.
The decimal-to-binary gap is part of it, but the operating system and preinstalled apps take most of the difference.
Yes. macOS has used decimal units since version 10.6, so a 1TB drive shows as roughly 1TB.
Last checked: 16 October 2026. Rules and dates can change, so confirm anything important with the official source linked above.