Skip to content

Commit 04b779b

Browse files
committed
图像
1 parent f304d1d commit 04b779b

File tree

93 files changed

+27
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+27
-0
lines changed

文件/055400588-image33.jpg

49.1 KB

文件/1-Propanol.svg

3.76 KB

文件/1.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
3+
def rename_svg_files(directory):
4+
"""
5+
重命名目录下所有以 .svg.png 结尾的文件,去掉 .png 后缀。
6+
7+
参数:
8+
directory (str): 要处理的目录路径,例如 '.' 表示当前目录。
9+
"""
10+
for filename in os.listdir(directory):
11+
# 检查文件是否以 .svg.png 结尾
12+
if filename.endswith(".svg.png"):
13+
# 生成新文件名:去掉最后的 4 个字符 (.png)
14+
new_filename = filename[:-4]
15+
# 获取完整路径
16+
old_path = os.path.join(directory, filename)
17+
new_path = os.path.join(directory, new_filename)
18+
# 重命名文件
19+
try:
20+
os.rename(old_path, new_path)
21+
print(f"已重命名: {filename} -> {new_filename}")
22+
except FileExistsError as e:
23+
print(f"{filename}, {e}")
24+
# 示例用法:替换为你的目录路径
25+
rename_svg_files('.') # 当前目录
26+
# 或者
27+
# rename_svg_files('/path/to/your/directory')

文件/2-Methyl-1-butanol.svg

3.67 KB

文件/2-Methyl-1-propanol.svg

4.2 KB

文件/2-Methyl-2-butanol.svg

6.89 KB

文件/2-Methyl-2-propanol.svg

6.05 KB

文件/2-Phenylethanol.svg

5.05 KB

文件/20150403_233753.jpg

33.5 KB

文件/25-NB-structure-general.png

5.39 KB

0 commit comments

Comments
 (0)