From 7263fb08e9170e90e67cb9b48884cc6a35cb3b62 Mon Sep 17 00:00:00 2001
From: Haitao <chenht2010@hotmail.com>
Date: 星期五, 13 十二月 2024 13:47:15 +0800
Subject: [PATCH] 识别结果中有英语时,缺少空格或者第一个单词的问题 (#2284)

---
 funasr/utils/misc.py |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/funasr/utils/misc.py b/funasr/utils/misc.py
index 4613cb3..eb17f97 100644
--- a/funasr/utils/misc.py
+++ b/funasr/utils/misc.py
@@ -94,3 +94,26 @@
     filename, extension = os.path.splitext(filename_with_extension)
     # 杩斿洖涓嶅寘鍚墿灞曞悕鐨勬枃浠跺悕
     return filename
+
+
+def smart_remove(path):
+    """Intelligently removes files, empty directories, and non-empty directories recursively."""
+    # Check if the provided path exists
+    if not os.path.exists(path):
+        print(f"{path} does not exist.")
+        return
+
+    # If the path is a file, delete it
+    if os.path.isfile(path):
+        os.remove(path)
+        print(f"File {path} has been deleted.")
+    # If the path is a directory
+    elif os.path.isdir(path):
+        try:
+            # Attempt to remove an empty directory
+            os.rmdir(path)
+            print(f"Empty directory {path} has been deleted.")
+        except OSError:
+            # If the directory is not empty, remove it along with all its contents
+            shutil.rmtree(path)
+            print(f"Non-empty directory {path} has been recursively deleted.")

--
Gitblit v1.9.1