def delete_directory(db, user_id, api_path):
db_dirname = from_api_dirname(api_path)<EOL>try:<EOL><INDENT>result = db.execute(<EOL>directories.delete().where(<EOL>and_(<EOL>directories.c.user_id == user_id,<EOL>directories.c.name == db_dirname,<EOL>)<EOL>)<EOL>)<EOL><DEDENT>except IntegrityError as error:<EOL><INDENT>if is_foreign_key_violation(error):<EOL><INDENT>raise DirectoryNotEmpty(api_path)<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>rowcount = result.rowcount<EOL>if not rowcount:<EOL><INDENT>raise NoSuchDirectory(api_path)<EOL><DEDENT>return rowcount<EOL>
Delete a directory.