Better detect whether user input is a file or a directory (re-write of rename())

Former-commit-id: b74a0973086ecf9967e40024e75a4c5cab730801
Former-commit-id: ea1a29a39eee6fa5b1da12f83455d3ea7da6c00a
This commit is contained in:
2023-03-02 01:32:40 -05:00
parent 6584686b2c
commit d1a994a103
2 changed files with 23 additions and 18 deletions
+4 -3
View File
@@ -32,11 +32,12 @@ def remote_list_gen(_client_device_name, _remote_dir): # prints all necessary r
def delete(_file_path, _target_database): # deletes a file or folder and/or marks it for deletion upon syncing
from shutil import rmtree
_directory = f"{home}/.local/share/sshyp/"
try:
if _file_path.endswith('/'): # TODO properly check if _file_path is a directory
rmtree(f"{home}/.local/share/sshyp/{_file_path}")
if isdir(_directory + _file_path):
rmtree(_directory + _file_path)
else:
remove(f"{home}/.local/share/sshyp/{_file_path}.gpg")
remove(f"{_directory}{_file_path}.gpg")
except FileNotFoundError:
print(f"location does not exist {_target_database}")
if _target_database == 'remotely':