3.31 上传 dm rewrite
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
path = "C:/Users/oyyz/Desktop/新建文件夹"
|
||||
|
||||
total_chars = 0
|
||||
# 遍历目录下的所有文件
|
||||
for filename in os.listdir(path):
|
||||
# 只处理txt文件
|
||||
if filename.endswith('.txt'):
|
||||
file_path = os.path.join(path, filename)
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
chars = len(content)
|
||||
total_chars += chars
|
||||
print(f"{filename}: {chars} 个字符")
|
||||
except Exception as e:
|
||||
print(f"读取文件 {filename} 时出错: {e}")
|
||||
|
||||
print(f"\n所有txt文件共包含 {total_chars} 个字符")
|
||||
|
||||
Reference in New Issue
Block a user