eolas/neuron/9445c5fd-135c-4b0b-a70c-7a6fd45d9d58/File_operations_in_Python.md
2025-04-05 10:32:40 +01:00

489 B

tags created
python
file-system
procedural
Friday, October 25, 2024

File operations in Python

Most create, delete, move etc operations invoke the inbuilt os module.

// Add directory CRUD operations in Python

Renaming files (moving)

import os
os.rename('original-file-name.txt', 'new-file-name.txt')

Deleting files

import os
os.remove('file-name.txt')

Check file exists

import os

file_exists = os.exists('/file/path')