This commit is contained in:
31
app.py
31
app.py
@@ -113,6 +113,37 @@ def delete_file():
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@app.route('/api/delete_multiple', methods=['DELETE'])
|
||||
def delete_multiple_files():
|
||||
"""Deletes multiple files."""
|
||||
data = request.get_json()
|
||||
paths = data.get('paths', [])
|
||||
|
||||
if not paths:
|
||||
return jsonify({"error": "No file paths provided"}), 400
|
||||
|
||||
errors = []
|
||||
success_count = 0
|
||||
|
||||
for path in paths:
|
||||
if not path or not os.path.exists(path):
|
||||
errors.append({"path": path, "error": "File not found"})
|
||||
continue
|
||||
|
||||
try:
|
||||
if os.path.isdir(path):
|
||||
errors.append({"path": path, "error": "Cannot delete directories"})
|
||||
else:
|
||||
os.remove(path)
|
||||
success_count += 1
|
||||
except Exception as e:
|
||||
errors.append({"path": path, "error": str(e)})
|
||||
|
||||
if not errors:
|
||||
return jsonify({"success": True, "message": f"{success_count} files deleted."})
|
||||
else:
|
||||
return jsonify({"success": False, "error": "Some files could not be deleted", "details": errors}), 500
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Run on localhost
|
||||
print("Starting File Explorer on http://127.0.0.1:5005")
|
||||
|
||||
Reference in New Issue
Block a user