-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWIN-GET.LRG.FILES.v1.py
55 lines (55 loc) · 2.89 KB
/
WIN-GET.LRG.FILES.v1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#-- !/usr/bin/env python3
#-- -*- coding: utf-8 -*-
#--
#-- ************************************************************************************************************:
#-- ****************************************** RETRIEVE LARGE FILES ********************************************:
#-- ************************************************************************************************************:
#-- Author: JBallard (JEB) :
#-- Date: 2024.8.15 :
#-- Script: WIN-GET.LRG.FILES.v1.py :
#-- Purpose: A Python Script that retrieves the largest files within a chosen subdirectory (recursively). :
#-- Class: python -m pip install glob :
#-- Class: python -m pip install argparse :
#-- Version: 1.0 :
#-- ************************************************************************************************************:
#-- ************************************************************************************************************:
#--
#-- ********************************************************:
#-- DEFINE PARAMS, CONSTANTS, CONFIG PATHS, CLASSES, & LIBS :
#-- ********************************************************:
import os
import sys
import glob
import argparse
#--
#-- DEFINE SEARCH PATH:
SRCHDir = os.path.join("//JBALLARD-9520", "C$", "0_SVN", "2_DEV")
LOGFile = os.path.join("//JBALLARD-9520", "C$", "0_SVN", "7_LOGS", "WIN-GET.LRG.FILES.v1.jeb")
NFiles = 5
#--
#-- FUNCTION - RETRIEVE LARGEST FILES WITHIN SUBDIRECTORY:
def RET_LARGE_Files(SRCHDir):
FILESizes = []
for dirpath, dirnames, filenames in os.walk(SRCHDir):
for filename in filenames:
FILEPath = os.path.join(dirpath, filename)
FILESize = os.path.getsize(FILEPath)
FILESizes.append((FILEPath, FILESize))
#-- SORT FILES VIA DESC SIZE:
FILESizes.sort(key=lambda x: x[1], reverse=True)
#--
#-- COPY "NFiles" LARGEST FILES TO THE DESTIANATION DIR::
with open(LOGFile, "w") as log:
for filepath, filesize in FILESizes[:NFiles]:
log.write(f"{filepath}\t\t{filesize} BYTES\n")
#--
#-- MAIN:
if __name__ == "__main__":
LRGFiles = RET_LARGE_Files(SRCHDir)
#-- PRINT FILEPATH & SIZE:
for FILEPath, FILESize in LRGFiles:
print(FILEPath, FILESize)
#--
#-- ********************************************************:
#-- END OF PYTHON SCRIPT :
#-- ********************************************************: