Skip to content

Commit 005bcd9

Browse files
committed
feat(qt-examples): add QFile_moveToTrash_pyqt6.py
1 parent a148d7f commit 005bcd9

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
__author__ = "ipetrash"
5+
6+
7+
from pathlib import Path
8+
9+
from PyQt6.QtCore import QFile
10+
11+
PATH: Path = Path(__file__).resolve()
12+
DIR: Path = PATH.parent
13+
14+
PATH_EXAMPLE: Path = DIR / f"{PATH.name}.txt"
15+
PATH_EXAMPLE.write_text("Hello World!")
16+
17+
print(f"Writing to file '{PATH_EXAMPLE.name}'")
18+
19+
file_path: str = str(PATH_EXAMPLE)
20+
file_obj: QFile = QFile(file_path)
21+
if file_obj.moveToTrash():
22+
print(f"File '{file_path}' was successfully moved to trash.")
23+
else:
24+
print(f"Failed to move file '{file_path}' to trash.")

0 commit comments

Comments
 (0)