code-learning/other/file-create.py

29 lines
1003 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import sys
import pyperclip # 如果你使用的是Windows或macOS需要安装这个库
# 获取当前脚本的路径
script_dir = os.path.dirname(os.path.abspath(__file__))
# 从剪贴板获取文件名列表
# 假设剪贴板中的文本是每行一个文件名
file_names = pyperclip.paste().strip().split('\n')
# 遍历文件名列表
for file_name in file_names:
# 去除文件名两端的空白字符
file_name = file_name.strip()
# 添加.md后缀
file_name_with_extension = f"{file_name}.md"
# 构建文件的完整路径
file_path = os.path.join(script_dir, file_name_with_extension)
# 创建文件
with open(file_path, 'w') as file:
# 如果你想在文件中写入一些初始内容,可以在这里写入
# 例如file.write("This is the content of the file.")
pass # 如果不需要写入内容使用pass语句或者省略with块内的内容
print(f"Files created successfully in {script_dir}")