DataHungry Documents
  • Welcom to DataHungry Documents
  • Library
    • Apache Airflow
    • Apache Iceberge
    • Bardapi
    • Binance
    • Databricks
    • Datetime
    • dotenv
    • FastAPI
    • Logging
    • Langchain
    • Minio (S3)
    • MLflow
    • OpenCV
    • Optuna
    • os
    • Pyiceberg
    • Pyspark
    • Pytest
    • Schedule
    • Sklearn & SHAP
    • SQLAlchemy
    • transformers (huggingface)
    • Firebase Firestore
  • Course
    • Web Scraping
    • Streamlit
    • NLP
  • Utility
    • Docker
    • Google Sheet
  • SQL
    • Basic SQL Statements
    • PL/SQL
    • Stored Procedure & Function
  • Scala
    • Setup
    • Spark
  • Cloud
    • AWS
    • Google Cloud
Powered by GitBook
On this page
  • Create path if not exists
  • Get files list
  • Split filename
  • Remove
  1. Library

os

Create path if not exists

import os
if not os.path.exists(path):
   os.mkdir(path)

filename = os.path.basename(path)
f, ext = os.path.splitext(filename)

os.environ.get(“key”, “default”)

Get files list

from glob import glob
files = glob(“*.csv”)

Split filename

# filename = "hello.txt"
# path = "/home/myname/hello.txt"
# f = "hello"
# ext = "txt"

filename = os.path.basename(path)
f, ext = os.path.splitext(filename)

Remove

import os, shutil

# remove file
if os.path.isfile("unwanted-file.txt"):
    os.remove("unwanted-file.txt")

# remove empty folder
if os.path.isdir("empty-dir"):
    os.rmdir("empty-dir")

# remove non-empty folder
if os.path.isdir("nonempty-dir"):
    shutil.rmtree("nonempty-dir")
PreviousOptunaNextPyiceberg

Last updated 1 year ago