TMP Folders and Files

Helper class for Temporary Folders and Files

class ozcore.core.path.tmp_folders.TMP_Folder(tmp_root='.', tmp_folder_name='tmp')[source]

Helper class for Temporary Folders and Files


  • tmp folder root

  • tmp folder path

  • cleans tmp folder files with given conditions


Useful for cleaning tmp folders espaecially when fetching csv files into tmp folders


from ozcore.core.path import TMP_Folder
tmp = TMP_folder(tmp_root="root/folder/path/", tmp_folder_name="tmp")

# ../../root_folder

# ../../root folder/tmp_folder_path

tmp.clean(glob="**/*.json", n=3)
# ... cleans all json files up to latest 3 in the tmp

tmp.clean(glob="*", n=-1)
# ... cleans all files in the tmp
property root

root folder path of the temporary folder as posixpath


posixpath path to root of the tmp folder

property path

path of the tmp folder as posixpath


posixpath to tmp folder

clean(glob, n=5, reverse=False)[source]

deletes old files in the tmp folder keeps last n files (sorted asc or desc)

  • n – number of files to keep!, default:5; -1 for all files

  • glob – search tmp folder to match files,

  • reverse – default False if sort files asc; for desc order set to True


# e.g. **/*.json for all json files in recursive subfolders
tmp_folder.clean(glob="**/*.json", n=3)

# e.g. * for all files in the folder
tmp_folder.clean(glob="*", n=-1)