1 Star 0 Fork 0

韩嘉浩/NewMarkdownFile

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
NewMarkdownFile.py 966 Bytes
一键复制 编辑 原始数据 按行查看 历史
韩嘉浩 提交于 2024-01-09 11:59 . hanjiahao add code and update README
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2024/1/9 11:37
# @Author : Han Jiahao
# @File : NewMarkdownFile.py
# @Software: PyCharm
import os
def create_dir_and_file(name):
current_path = os.getcwd() # 获取当前路径
dir_path = os.path.join(current_path, name) # 创建同名目录的路径
file_path = os.path.join(current_path, name, name + ".md") # 创建同名文件的路径
if os.path.exists(dir_path): # 如果目录已存在,直接返回
print(f"Directory {name} already exists!")
return
os.mkdir(dir_path) # 创建同名目录
with open(file_path, "w") as f: # 在同名目录下创建同名文件
f.write(f"# {name}")
print(f"Directory ./{name} and file ./{name}/{name}.md created successfully!")
input("Press Enter to exit...")
if __name__ == "__main__":
print("===NewMarkdownFile===")
name = input("Enter a file name: ")
create_dir_and_file(name)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/han-jiahao666/new-markdown-file.git
git@gitee.com:han-jiahao666/new-markdown-file.git
han-jiahao666
new-markdown-file
NewMarkdownFile
master

搜索帮助