Skip to main content

get_valid_filename

Return the given string converted to a string that can be used for a clean filename. Remove leading and trailing spaces; convert other spaces to underscores; and remove anything that is not an alphanumeric, dash, underscore, or dot.

def get_valid_filename(
name: string
) - > string

Return the given string converted to a string that can be used for a clean filename. Remove leading and trailing spaces; convert other spaces to underscores; and remove anything that is not an alphanumeric, dash, underscore, or dot.

Parameters

NameTypeDescription
namestringThe raw string or path component to be sanitized into a valid filename.

Returns

TypeDescription
stringA sanitized string safe for use as a filename, containing only alphanumeric characters, dashes, underscores, and dots.