File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ # scan the current directory and all subdirectories and display the size
2
+
3
+ ## Introduction
4
+ ```
5
+ It is a simple java code which help to find size of sub directory and files inside a given directory
6
+ ```
7
+
8
+
9
+ ## How to use the code
10
+ ```
11
+ 1. Download the given code
12
+ 2. Run the size.java file
13
+ 3. Enter the path of your Folder
14
+ 3. The size of directory in bytes, KiloBytes, MegaBytes will be shown
15
+ ```
16
+ ## Output
17
+
18
+ ![ endpoint] ( https://github.com/Tejas1510/hacking-tools-scripts/blob/size/Java/SizeOfDirectory/images/image1.png )
19
+
20
+ ![ built with love] ( https://forthebadge.com/images/badges/built-with-love.svg )
21
+
22
+ Check out my Github profile [ Tejas1510!] ( https://github.com/Tejas1510 )
Original file line number Diff line number Diff line change
1
+ package FileCounter ;
2
+ import java .io .File ;
3
+ import java .util .*;
4
+ public class filecounter {
5
+ public static int countDirectory =0 ;
6
+ public static long countsize (File directory ){
7
+ long dictsize =0 ;
8
+ for (File file : directory .listFiles ()) {
9
+ if (file .isFile ()) {
10
+ dictsize =dictsize +file .length ();
11
+ }
12
+ if (file .isDirectory ()) {
13
+ dictsize += countsize (file );
14
+ }
15
+ }
16
+ return dictsize ;
17
+ }
18
+ public static void main (String args []) {
19
+ Scanner s = new Scanner (System .in );
20
+ System .out .println ("Enter the Path of your directory : " );
21
+ String path = s .next ();
22
+ File file = new File (path );
23
+ long dictsize = filecounter .countsize (file );
24
+ System .out .println ("The size of entered Directory in Bytes is : " +dictsize +" Bytes" );
25
+ System .out .println ("The size of entered Directory in Kilo Bytes(KB) is : " +dictsize /1024 +" KiloBytes" );
26
+ System .out .println ("The size of entered Directory in Mega Bytes(MB) is : " +dictsize /(1024 *1024 )+" MegaBytes" );
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments