Skip to content

Commit 78d082d

Browse files
committed
add fs.rm_file
1 parent 11f5142 commit 78d082d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pyfatfs/PyFatFS.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pyfatfs.errors import DirectoryExpected, \
1818
FileExpected, DirectoryNotEmpty, RemoveRootError, \
1919
FileExists
20+
from pyfatfs._exceptions import PyFATException
2021

2122
from pyfatfs import FAT_OEM_ENCODING
2223
from pyfatfs.DosDateTime import DosDateTime
@@ -408,7 +409,7 @@ def removetree(self, dir_path: str):
408409
except RemoveRootError:
409410
pass
410411

411-
def remove(self, path: str):
412+
def _rm_file_check(self, path: str):
412413
"""Remove a file from the filesystem.
413414
414415
:param path: `str`: Path of file to remove
@@ -422,6 +423,19 @@ def remove(self, path: str):
422423
base = dir_entry.get_parent_dir()
423424
self._remove(base, dir_entry)
424425

426+
def rm_file(self, path):
427+
"""Remove a file from the filesystem.
428+
429+
:param path: `str`: Path of file to remove
430+
"""
431+
dir_entry = self._get_dir_entry(path)
432+
try:
433+
base = dir_entry.get_parent_dir()
434+
except PyFATException:
435+
# Cannot query parent directory of root directory
436+
return
437+
self._remove(base, dir_entry)
438+
425439
def _remove(self, parent_dir: FATDirectoryEntry,
426440
dir_entry: FATDirectoryEntry):
427441
"""Remove directory entry regardless of type (dir or file).

0 commit comments

Comments
 (0)