139 Star 662 Fork 253

mktime/python-learn

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
downloads
images
models
qsbk
.gitignore
2.png
ExcelHelper.py
FSM.py
LICENSE
README.md
SSEncrypt.module
ai-agent.py
arch-install.md
audio-rtmp.py
auto_build.py
baidu_ocr.py
balance_config.ini
balance_query.py
balance_query_batch.txt
bencode.py
bloom_1.cpp
bloom_1.py
bloom_2.py
capture-camera.py
check_https_domain_exp_date.py
cnn-demo.py
contacts.xml
crack_test.py
crack_wifi.txt
data-structure.py
dcm2jpg.py
decrypt_remmina.py
delicious.md
delicious.xml
demo.c
dht_client.py
dou2.py
download.py
egcd.py
export_delicious.sh
face-detect.py
fetchurl.py
find_repeat.py
findbig.py
five-elements.py
flv2mp4.py
get_bookmarks.py
get_version.py
gpt35.py
howto_terminate_thread.py
http_proxy.py
i3_config
import_ess_picture.py
ipfind.py
joseph-cycle.py
kimi.py
learn-class.py
learn-docker.md
learn-thread.py
learn_thread.py
linux-tips.md
merge_excel.py
monitor.sh
mydict.py
mysql_init.sql
new.txt
ocr_words.py
orm.py
parse_excel.py
parse_json.py
payload.py
pm25.py
print_ascii.py
problem.py
python-learn-1.py
python-learn-2.py
qiubai.py
remote.sh
repeated.sql
rpc_server.py
scan.py
scan2.py
score.py
screen.sh
send_fangtang.py
sina_user.json
smz_report.py
sock5.py
sock_client.py
sock_serv.py
start-audio.sh
sync_aliyun.py
system_update.py
template.xml
test_img2pdf.py
test_pdf2images.py
torrent_client.py
totp.py
tray.py
update.ico
urls.txt
v2ex.py
v2ex.txt
wifi-keep.sh
wind_crawl.py
x_test.npy
x_train.npy
xml2vcf.py
y_test.npy
y_train.npy
Clone or Download
findbig.py 2.72 KB
Copy Edit Raw Blame History
mktime authored 10 years ago . findbig file
import os.path
from os.path import isfile, isdir, join, getsize
from sys import argv, exit
import getopt
def find_big_directory(p, big_size):
total_size = 0
try:
items = os.listdir(p)
except:
items = []
for item in items:
fp = join(p, item)
if isfile(fp):
total_size = total_size + getsize(fp)
else:
total_size = total_size + find_big_directory(fp, big_size)
if total_size > big_size:
pprint(p, total_size)
return total_size
def find_big_file(p, big_size):
total_size = 0
try:
items = os.listdir(p)
except:
items = []
for item in items:
fp = join(p, item)
if isfile(fp):
total_size = getsize(fp)
if total_size > big_size:
pprint(fp, total_size)
else:
find_big_file(fp, big_size)
def pprint(p, size):
if size < 1024:
print "[%s]: %.2f Bytes" % (p, size)
elif size < (1024 * 1024):
print "[%s]: %.2f Kib" % (p, float(size) / 1024)
elif size < (1024 * 1024 * 1024):
print "[%s]: %.2f Mib" % (p, float(size) / (1024 * 1024))
elif size < (1024 * 1024 * 1024 * 1024):
print "[%s]: %.2f Gib" % (p, float(size) / (1024 * 1024 * 1024))
else:
print "[%s]: %.2f Tib" % (p, float(size) / (1024 * 1024 * 1024 * 1024))
def usage():
print '''
python findbig.py [options]
-t, --type dir or file, find bing dir or find big file
-d, --dir the dir to find
-m, --minsize find dir or file size large than minsize
-h, --help show help
-v, --version show version
'''
exit(0)
if __name__ == '__main__':
dst_dir = ""
big_size = ""
query_type = ""
try:
options, args = getopt.getopt(argv[1:], "hvt:d:m:", ["help", "type=" "dir=", "minsize="])
except:
usage()
for o, v in options:
if o in ("-h", "--help"):
usage()
if o in ("-v", "--version"):
print "0.0.1 --by withrock"
exit(0)
if o in ("-t", "--type"):
if v in ("dir", "file"):
query_type = v
else:
usage()
if o in ("-d", "--dir"):
dst_dir = v
if not isdir(dst_dir):
print "dir invalid."
usage()
if o in ("-m", "--minsize"):
try:
big_size = long(v)
except:
print "minsize invalid."
usage()
if query_type == "" or dst_dir == "" or big_size == "":
usage()
if query_type == "dir":
find_big_directory(dst_dir, big_size)
else:
find_big_file(dst_dir, big_size)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mktime/python-learn.git
git@gitee.com:mktime/python-learn.git
mktime
python-learn
python-learn
master

Search