INNER CODE UNIT · Python
scan_directory
AnsahMohammad/shots-studio · legacy/web/app.py:42
def scan_directory():
global images
data = request.json
directory = data.get("path", os.getcwd())
if not os.path.exists(directory):
return jsonify({"success": False, "error": "Directory does not exist"}), 400
images.clear() # Clear existing images
for root, _, files in os.walk(directory):
for file in files:
if os.path.splitext(file)[1].lower() in ALLOWED_IMAGE_EXTENSIONS:
abs_path = os.path.abspath(os.path.join(root, file))
img = Image(abs_path)
if img not in images:
images.append(img)
return jsonify({"success": True, "count": len(images)})