Skip to content

Commit

Permalink
1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
foxfollow committed Dec 11, 2023
1 parent c2df3e6 commit 6891d72
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.xlsx
build
*.spec
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
# FolderSizeAnalyzer
Used for analyze folder and subfolder for their size, than make excel file as output. For Windows

## Usage
Main .exe file in `dist\`

Use `.exe` in folder `dist` or `.py` (Note: for using `.py` should install requirments)

MIT License
### Run script 1 exmaple
```
searchFoldersAnalyzer.exe C:\ Windows OneDrive
```

where `C:\` folder to search and `Windows` and `OneDrive` is folders to skip

### Run script 2 exmaple
```
searchFoldersAnalyzer.exe
```
scipt will ask which folder to scan and which folders to skip

## Building
- Check Requirments for building
- Run `build.ps1`
## Requirments
Windows
Tested on Python 3.10
Python libraries `openpyxl`

### Installing requirments
```
pip install openpyxl
```

### Requirments for building
`pyinstaller` and `openpyxl`

ensure that you have correct path to your pyinstaller and change `build.ps1` first row if needed


## MIT License

Copyright (c) 2023 Heorhii Savoiskyi
8 changes: 8 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Import-Module Microsoft.PowerShell.Utility
$pythonScriptsPath = Join-Path $env:APPDATA "Python\Python310\Scripts"
$env:Path += ";$pythonScriptsPath"

$params = "--onefile --hidden-import openpyxl"
$command = "pyinstaller .\searchFoldersAnalyzer.py $params --name searchFoldersAnalyzer.exe"

Invoke-Expression $command
Binary file added dist/searchFoldersAnalyzer.exe
Binary file not shown.
34 changes: 20 additions & 14 deletions searchFoldersAnalyzer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import pandas as pd
# import pandas as pd
from openpyxl import Workbook
from datetime import datetime
import sys
Expand Down Expand Up @@ -38,8 +38,9 @@ def scan_folders(folder_path):

for i, folder in enumerate(all_folders):
# Skip folders...
# if "Windows" in folder or "OneDrive" in folder or "OneDrive - SCPC of 3SCIP" in folder:
# continue
folder_names = folder.split(os.sep)
if any(skip_folder in folder_names for skip_folder in folders_to_skip):
continue

try:
folder_size = get_folder_size(folder)
Expand All @@ -62,12 +63,12 @@ def scan_folders(folder_path):
return folder_sizes


def create_excel(folder_sizes):
df = pd.DataFrame(folder_sizes, columns=['Folder Path', 'Size', 'Unit'])
now = datetime.now()
date_time = now.strftime("%m-%d-%H-%M")
excel_path = os.path.join(folder_path, f'outp{date_time}.xlsx')
df.to_excel(excel_path, index=False)
# def create_excel(folder_sizes):
# df = pd.DataFrame(folder_sizes, columns=['Folder Path', 'Size', 'Unit'])
# now = datetime.now()
# date_time = now.strftime("%m-%d-%H-%M")
# excel_path = os.path.join(folder_path, f'outp{date_time}.xlsx')
# df.to_excel(excel_path, index=False)


def create_excel_xl(folder_sizes):
Expand All @@ -93,8 +94,17 @@ def create_error_log(error_name):
with open(log_path, 'a') as f:
f.write(f"{date_time2}: {error_name}\n")


# MAIN
# Get folder path from command line arguments or user input
folder_path = sys.argv[1] if len(sys.argv) > 1 else input("Enter the folder path: ")

# Collect all command line arguments after the first one into a list
if len(sys.argv) > 2:
folders_to_skip = sys.argv[2:]
else:
user_input = input("Enter the folders to skip separated by commas, or press Enter to skip none: ")
folders_to_skip = [folder.strip() for folder in user_input.split(",")] if user_input else []

print("Scanning folders...")
try:
folder_sizes = scan_folders(folder_path)
Expand All @@ -105,7 +115,3 @@ def create_error_log(error_name):
create_error_log(str(e))
print("An error occurred. Please check the error log.")
input("Press Enter to exit...")

input("Press Enter to exit...")


0 comments on commit 6891d72

Please sign in to comment.