File size: 810 Bytes
54bc341
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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}")