Spaces:
Sleeping
Sleeping
| import re,os | |
| def sanitize_filename(filename): | |
| # Windows不允许的字符 | |
| invalid_chars = r'[<>:"/\\|?*\x00-\x1F]' | |
| # 使用正则表达式替换无效字符为空字符串 | |
| sanitized = re.sub(invalid_chars, '_', filename) | |
| # 限制文件名长度(最大为255个字符) | |
| sanitized = sanitized[:255] | |
| # 去掉前后空格 | |
| sanitized = sanitized.strip() | |
| return sanitized | |
| def deleteFileList(fileList): | |
| for file_path in fileList: | |
| try: | |
| os.remove(file_path) | |
| print(f"成功删除文件: {file_path}") | |
| except FileNotFoundError: | |
| print(f"文件未找到,无法删除: {file_path}") | |
| except OSError as e: | |
| print(f"删除文件 {file_path} 时发生错误: {e}") | |