diff --git a/routes/__pycache__/room_files.cpython-313.pyc b/routes/__pycache__/room_files.cpython-313.pyc index 3c18ed3..e94e7fd 100644 Binary files a/routes/__pycache__/room_files.cpython-313.pyc and b/routes/__pycache__/room_files.cpython-313.pyc differ diff --git a/routes/room_files.py b/routes/room_files.py index 294710c..5bd7da9 100644 --- a/routes/room_files.py +++ b/routes/room_files.py @@ -303,6 +303,23 @@ def rename_room_file(room_id): # Update RoomFile entry rf.name = new_name rf.modified = os.path.getmtime(new_path) + + # If this is a folder, update paths of all contained files and subfolders + if os.path.isdir(new_path): + old_folder_path = os.path.join(rel_path, old_name) if rel_path else old_name + new_folder_path = os.path.join(rel_path, new_name) if rel_path else new_name + + # Get all files and folders that are under the old path + contained_items = RoomFile.query.filter( + RoomFile.room_id == room_id, + RoomFile.path.like(f"{old_folder_path}%") + ).all() + + # Update their paths + for item in contained_items: + # Replace the old folder path with the new one in the item's path + item.path = item.path.replace(old_folder_path, new_folder_path, 1) + db.session.commit() return jsonify({'success': True, 'old_name': old_name, 'new_name': new_name})