How to Check File Size in 10 Programming Languages
C, C++, Java, Lua, Perl, Python, PHP, C#, JavaScript/Nodejs and Go.
Today, once again, we are going to exercise our knowledge by creating routines that can be useful in different situations. And this time we will see how to know the size of a file in 10 different programming languages, they are: C, C++, Java, C#, [PHP] (https://terminalroot.com/tags#php), Lua, Perl, Python, JavaScript/Node.js and Go/Golang.
As in the article:
I’ll just post the code for each of them!
The file.iso
file is fictitious and you must replace it with a valid file on your computer to carry out the tests.
You can compare the result using the command: du -h file.iso
.
01. C
filesize.c
gcc filesize.c && ./a.out
02. C++
filesize.cpp
g++ filesize.cpp && ./a.out
03. Java
FileSize.java
javac FileSize.java && java FileSize
04. Lua
filesize.lua
lua filesize.lua
05. Perl
filesize.pl
perl filesize.pl
06. Python
filesize.py
python filesize.py
07. PHP
filesize.php
php filesize.php
08. C#
dotnet new console -o FileSize && cd FileSize && vim Program.cs
dotnet run
09. JavaScript/Node.js
filesize.js
node filesize.js
10. Golang/Go
filesize.go
go build filesize.go && ./filesize
ougo run filesize.go
Until the next article!
clanguage cpp java lua perl python php csharp javascript nodejs go programming langs
Comments