os module ရှိ path.isfile method

path.isfile method သည် parameter တွင်ဖော်ပြထားသော ဖိုင်ရှိ/မရှိ စစ်ဆေးပေးသည်။ ထို့အပြင် ဤ method ကို parameter တွင်ဖော်ပြထားသော path သည် ဖိုင်တစ်ခုဟုတ်/မဟုတ် ဆုံးဖြတ်ရန်လည်း အသုံးပြုနိုင်ပါသည်။ Method သည် boolean တန်ဖိုးပြန်ပေးသည်- အကယ်၍ path သည် ဖိုင်တစ်ခုဖြစ်ပါက True ပြန်ပေးပြီး၊ မဟုတ်ပါက False ပြန်ပေးသည်။

ဖွဲ့စည်းပုံ

pythonimport os

print(os.path.isfile(လမ်းကြောင်း))

ဥပမာ

ပေးထားသော လမ်းကြောင်းသည် ဖိုင်တစ်ခုဟုတ်/မဟုတ် ထပ်မံစစ်ဆေးကြည့်ရအောင်-

pythonimport os

print(os.path.isfile('file.txt'))

ကုဒ်အလုပ်လုပ်ပြီးနောက် ရလဒ်-

pythonTrue

ဥပမာ

ယခု ပေးထားသော လမ်းကြောင်းသည် ဖိုင်တစ်ခုဟုတ်/မဟုတ် စစ်ဆေးကြည့်ရအောင်-

pythonimport os

print(os.path.isfile('dir'))

ကုဒ်အလုပ်လုပ်ပြီးနောက် ရလဒ်-

pythonFalse

ဤအကြောင်းအရာများကိုလည်း ကြည့်ရှုပါ

  • path.isdir method of os module,
    which checks the existence of a folder
  • path.exists method of os module,
    which checks the existence of a path
  • copy2 method of shutil module,
    which copies a file with metadata
  • rename method of os module,
    which renames a file and folder
  • path.join method of os module,
    which joins paths
  • path.getsize method of os module,
    which returns the size of a path in bytes