File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed
Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -329,16 +329,22 @@ def md5(filename):
329329
330330
331331def get_folder_size_in_gb (folder ):
332+ # Check if the folder exists; if not, return 0 GB
332333 if not os .path .exists (folder ):
333334 return 0
334- total_size = os .path .getsize (folder )
335- for item in os .listdir (folder ):
336- path = os .path .join (folder , item )
337- if os .path .isfile (path ):
338- total_size += os .path .getsize (path )
339- elif os .path .isdir (path ):
340- total_size += get_folder_size_in_gb (path )
341- return total_size / 1000 / 1000 / 1000 # GB: decimal system (1000^3)
335+
336+ total_size = 0 # Initialize total size accumulator (in bytes)
337+
338+ # Walk through the folder and all its subdirectories
339+ for root , dirs , files in os .walk (folder ):
340+ for f in files :
341+ # Construct full path to the file
342+ fp = os .path .join (root , f )
343+ # Add the file size to total_size
344+ total_size += os .path .getsize (fp )
345+
346+ # Convert bytes to gigabytes using decimal system (1 GB = 1000^3 bytes)
347+ return total_size / (1000 ** 3 )
342348
343349
344350def delete_files_in_folder (folder ):
You can’t perform that action at this time.
0 commit comments