title: Loop to pull file size, folder size, and directory size?
body: <p>I'm attempting to scan a directory and all subfolders and files within in. I would also like to pull the file size for every folder and file. I'm a bit stumped on the best technique for this. Here's what I have so far. The total directory output is incorrect and so is the total folder size.</p>
  
  <pre><code>import os
  import pandas as pd
  import time
  from pathlib import Path
  
  # sets the display so that when the code prints, it is readable
  pd.set_option('display.max_rows', 3000)
  pd.set_option('display.max_columns', 10)
  pd.set_option('display.width', 3000)
  
  # Initialize the dataframe
  col_names = ['directory', 'file name', 'file size', 'file date', 'total in directory', 'total in folder']
  files = pd.DataFrame(columns=col_names)
  
  dir_path = Path('G:/OM/Permits')
  for dirpath, dirnames, filenames in os.walk(dir_path):
      print(dirpath)
      files.loc[dirpath, 'directory'] = dirpath
      total_file = sum(os.path.getsize(f) for f in os.scandir(dirpath) if os.path.isfile(f))
      files.loc[total_file, 'total in directory'] = total_file
      for file_size in dirpath:
          total_file = round((sum(os.path.getsize(f) for f in os.scandir(dirpath) if os.path.isfile(f)) / 1048576), 3)
          files.loc[total_file, 'total in folder'] = total_file
      with os.scandir(dirpath) as i:
       for entry in i:
           if entry.is_file():
               print(entry.name)
               files.loc[entry.name, 'file name'] = entry.name
               file_size = round((os.path.getsize(entry) / 1048576),3)
               files.loc[file_size, 'file size'] = file_size
               files_date = time.strftime('%m/%d/%Y', time.gmtime(os.path.getmtime(entry)))
               files.loc[files_date, 'file date'] = files_date
  
  df = pd.DataFrame(files)
  df['file size'] = df['file size'].shift(periods=-1)
  df['file date'] = df['file date'].shift(periods=-2)
  df.reset_index(drop=True, inplace=True)
  df.dropna(how='all')
  print(df)
  #df.to_csv('G Drive List of Files.csv')
  </code></pre>
  
  <p>This is a portion of my output.</p>
  
  <pre><code>                                             directory                                          file name file size   file date total in directory total in folder
  0                                         G:\OM\Permits                                                NaN       NaN         NaN                NaN             NaN
  1                                                   NaN                                                NaN       NaN         NaN            1394256             NaN
  2                                                   NaN                                                NaN       NaN         NaN                NaN            1.33
  3                                                   NaN                           3-Letter_PermitCodes.pdf     0.136  04/01/2019                NaN             NaN
  </code></pre>