Skip to content

Commit a06cc1a

Browse files
authored
Updated snipped file-operations.md for spelling, comments and missing imports
1 parent 97a828b commit a06cc1a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

snippets/python/file-handling/file-operations.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,56 @@
11
---
22
title: File Operations Class
3-
description: It's an class where you have some functions for file Opertation
3+
description: It's an class where you have some functions for file Operation
44
author: mrcool7387
55
tags: python,file operation,class
66
---
77

88

99
```py
10+
import zipfile
11+
import os
12+
import shutil
13+
1014
class FileOperations:
1115
def create_file(self, file_path: str):
16+
"""Creates an empty File"""
1217
with open(file_path, 'w') as f:
1318
pass
1419

1520
def delete_file(self, file_path: str):
21+
"""Deletes a File"""
1622
if os.path.exists(file_path):
1723
os.remove(file_path)
1824

1925
def write_file(self, file_path: str, context: str):
26+
"""Writes some text to a file. '\n' is used fo a new Line"""
2027
with open(file_path, 'w') as f:
2128
f.write(context)
2229

2330
def move_file(self, src: str, dest: str):
31+
"""Moves a File form its Source to it's destination"""
2432
shutil.move(src, dest)
2533

2634
def copy_file(self, src: str, dest: str):
35+
"""Copies a File form its Source to it's destination"""
2736
shutil.copy(src, dest)
2837

2938
def get_file_size(self, file_path: str):
39+
"""Returns the File size of the selected File"""
3040
return os.path.getsize(file_path) if os.path.isfile(file_path) else 0
3141

3242
def get_file_extension(self, file_path: str):
43+
"""Returns the Type/Extension of the selected File"""
3344
return os.path.splitext(file_path)[1]
3445

3546
def zip_files(self, files: list[str], zip_name: str):
47+
"""Compresses some selected Files, don't forget the '.zip' at the end of the ZIP-File-Name"""
3648
with zipfile.ZipFile(zip_name, 'w') as zf:
3749
for file in files:
3850
zf.write(file)
3951

4052
def extract_zip(self, zip_name: str, extract_to: str):
53+
"""Extracts from a selected ZIP File to a Destination"""
4154
with zipfile.ZipFile(zip_name, 'r') as zf:
4255
zf.extractall(extract_to)
4356

0 commit comments

Comments
 (0)