Spaces:
Running
Running
Update tools/file_manager_server.py
Browse files- tools/file_manager_server.py +26 -16
tools/file_manager_server.py
CHANGED
|
@@ -2,6 +2,7 @@ import shutil
|
|
| 2 |
import os
|
| 3 |
from pathlib import Path
|
| 4 |
from typing import List
|
|
|
|
| 5 |
import mimetypes
|
| 6 |
|
| 7 |
|
|
@@ -64,11 +65,14 @@ async def organize_by_type(files: List[Path], base_dir: Path) -> dict:
|
|
| 64 |
|
| 65 |
# Move file
|
| 66 |
dest = cat_dir / file.name
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
return {
|
| 74 |
'success': True,
|
|
@@ -93,11 +97,14 @@ async def organize_by_date(files: List[Path], base_dir: Path) -> dict:
|
|
| 93 |
|
| 94 |
# Move file
|
| 95 |
dest = date_dir / file.name
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
return {
|
| 103 |
'success': True,
|
|
@@ -133,11 +140,14 @@ async def organize_by_size(files: List[Path], base_dir: Path) -> dict:
|
|
| 133 |
|
| 134 |
# Move file
|
| 135 |
dest = cat_dir / file.name
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
return {
|
| 143 |
'success': True,
|
|
@@ -170,4 +180,4 @@ async def rename_file(file_path: str, new_name: str) -> dict:
|
|
| 170 |
}
|
| 171 |
|
| 172 |
except Exception as e:
|
| 173 |
-
return {'error': str(e), 'success': False}
|
|
|
|
| 2 |
import os
|
| 3 |
from pathlib import Path
|
| 4 |
from typing import List
|
| 5 |
+
from datetime import datetime
|
| 6 |
import mimetypes
|
| 7 |
|
| 8 |
|
|
|
|
| 65 |
|
| 66 |
# Move file
|
| 67 |
dest = cat_dir / file.name
|
| 68 |
+
try:
|
| 69 |
+
shutil.move(str(file), str(dest))
|
| 70 |
+
|
| 71 |
+
if category not in moved_files:
|
| 72 |
+
moved_files[category] = []
|
| 73 |
+
moved_files[category].append(file.name)
|
| 74 |
+
except Exception as e:
|
| 75 |
+
print(f"Error moving {file.name}: {e}")
|
| 76 |
|
| 77 |
return {
|
| 78 |
'success': True,
|
|
|
|
| 97 |
|
| 98 |
# Move file
|
| 99 |
dest = date_dir / file.name
|
| 100 |
+
try:
|
| 101 |
+
shutil.move(str(file), str(dest))
|
| 102 |
+
|
| 103 |
+
if date_folder not in moved_files:
|
| 104 |
+
moved_files[date_folder] = []
|
| 105 |
+
moved_files[date_folder].append(file.name)
|
| 106 |
+
except Exception as e:
|
| 107 |
+
print(f"Error moving {file.name}: {e}")
|
| 108 |
|
| 109 |
return {
|
| 110 |
'success': True,
|
|
|
|
| 140 |
|
| 141 |
# Move file
|
| 142 |
dest = cat_dir / file.name
|
| 143 |
+
try:
|
| 144 |
+
shutil.move(str(file), str(dest))
|
| 145 |
+
|
| 146 |
+
if category not in moved_files:
|
| 147 |
+
moved_files[category] = []
|
| 148 |
+
moved_files[category].append(file.name)
|
| 149 |
+
except Exception as e:
|
| 150 |
+
print(f"Error moving {file.name}: {e}")
|
| 151 |
|
| 152 |
return {
|
| 153 |
'success': True,
|
|
|
|
| 180 |
}
|
| 181 |
|
| 182 |
except Exception as e:
|
| 183 |
+
return {'error': str(e), 'success': False}
|