os module ၏ path.getsize method
path.getsize method သည် file တစ်ခု သို့မဟုတ် folder တစ်ခု၏ အရွယ်အစားကို bytes ဖြင့် ပြန်ပေးပါသည်။ method ၏ parameter တွင် လိုအပ်သော file သို့မဟုတ် folder ၏ path ကို ထည့်သွင်းပေးရပါမည်။ သတ်မှတ်ထားသော path မရှိပါက OSError exception ကို ပြန်ပေးပါမည်။
Syntax
import os
print(os.path.getsize(path))
နမူနာ
ကျွန်ုပ်တို့၏ file ၏ အရွယ်အစားကို bytes ဖြင့် သိရှိကြပါစို့:
import os
print(os.path.getsize('file.txt'))
run ထားသော code ၏ ရလဒ်:
210
နမူနာ
File ၏ အရွယ်အစားကို kilobytes ဖြင့် သိရှိကြပါစို့။
ထိုသို့ပြုလုပ်ရန် ရရှိလာသော တန်ဖိုးကို 1000 ဖြင့် စားပေးရုံသာဖြစ်ပါသည်:
import os
print(os.path.getsize('file.txt') / 1000)
Run ထားသော code ၏ ရလဒ်:
0.21
ဆက်လက်လေ့လာရန်
-
disk_usagemethod ofshutilmodule,
which returns disk usage statistics -
statmethod ofosmodule,
which returns the status of a path -
path.existsmethod ofosmodule,
which checks the existence of a path -
path.isdirmethod ofosmodule,
which checks the existence of a directory -
path.isfilemethod ofosmodule,
which checks the existence of a file