1
- # Script Name : folder_size.py
2
- # Author : Craig Richards
3
- # Created : 19th July 2012
4
- # Last Modified :
5
- # Version : 1.0
1
+ # Script Name : folder_size.py
2
+ # Author : Craig Richards
3
+ # Created : 19th July 2012
4
+ # Last Modified : 14 February 2016
5
+ # Version : 1.0.1
6
6
7
- # Modifications :
7
+ # Modifications : 1.0.1 - Tidy up comments and syntax, add main() function
8
8
9
- # Description : This will scan the current directory and all subdirectories and display the size.
9
+ # Description : This will scan the current directory and all subdirectories and display the size.
10
10
11
- import os # Load the library module
11
+ import os # Load the library module
12
12
13
- directory = '.' # Set the variable directory to be the current directory
14
- dir_size = 0 # Set the size to 0
15
- for (path , dirs , files ) in os .walk (directory ): # Walk through all the directories
16
- for file in files : # Get all the files
17
- filename = os .path .join (path , file )
18
- dir_size += os .path .getsize (filename ) # Get the sizes, the following lines print the sizes in bytes, Kb, Mb and Gb
19
- print "Folder Size in Bytes = %0.2f Bytes" % (dir_size )
20
- print "Folder Size in Kilobytes = %0.2f KB" % (dir_size / 1024.0 )
21
- print "Folder Size in Megabytes = %0.2f MB" % (dir_size / 1024 / 1024.0 )
22
- print "Folder Size in Gigabytes = %0.2f GB" % (dir_size / 1024 / 1024 / 1024.0 )
13
+ directory = '.' # Set the variable directory to be the current directory
14
+ dir_size = 0 # Set the size to 0
15
+
16
+ def main ():
17
+ for (path , dirs , files ) in os .walk (directory ): # Walk through all the directories
18
+ for file in files : # Get all the files
19
+ filename = os .path .join (path , file )
20
+ dir_size += os .path .getsize (filename ) # Get the sizes, the following lines print the sizes in bytes, Kb, Mb and Gb
21
+ print "Folder Size in Bytes = %0.2f Bytes" % (dir_size )
22
+ print "Folder Size in Kilobytes = %0.2f KB" % (dir_size / 1024.0 )
23
+ print "Folder Size in Megabytes = %0.2f MB" % (dir_size / 1024 / 1024.0 )
24
+ print "Folder Size in Gigabytes = %0.2f GB" % (dir_size / 1024 / 1024 / 1024.0 )
25
+
26
+ if __name__ == '__main__' :
27
+ main ()
0 commit comments