# mPy: Utilities to handle file based objects like database files
# Copyright by Anthony Vogelaar, Perth Scotland
# rev 0.10  2026-06-11  initial release

import	os

# Implements:
# fExists(fn)					-->  bool
# fSize(fn)						-->  int
# fRemove(fn)					-->  bool
# fRename(fn_old, fn_new)		-->  bool

# ===================== utilities =======================

# Returns True if file exists
def fExists(fn):
    try:
        f = open(fn, 'r')
        f.close()
        return True
    except: pass


# return file size in bytes
def fSize(fn='test.log'):
    return os.stat(fn)[6]


# return True if file deleted
def fRemove(fn):
    try:
        os.remove(fn)
        return True
    except: pass


# return True on success
def fRename(fn_old, fn_new):
    if fExists(fn_old) and not fExists(fn_new):
        os.rename(fn_old, fn_new)
        return True

# ========================== end ============================

