V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
will2k
V2EX  ›  Python

GitHub Action 使用 Python 创建目录

  •  
  •   will2k · 266 天前 · 809 次点击
    这是一个创建于 266 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想用 GitHub Action 自动执行一个 python 文件,但是实际执行的和我在本地执行的结果不一样。

    我要根据路径创建文件夹,但是创建出来的是命名为路径的一个文件夹?

    比如:我要创建一个路径为./archives/key/month的文件夹,如果其中任何一个不存在就自动创建,也就是三个文件夹。

    但是却只生成了一个名称为archives/key/month的文件夹。

    代码是这么写的

    path = os.path.join('./archives',key,year,month)
    os.makedirs(path, exist_ok=True)
    

    所以大佬们这问题咋解决,第一次遇到这个奇怪的问题

    2 条回复    2023-08-16 18:41:45 +08:00
    AoEiuV020JP
        1
    AoEiuV020JP  
       266 天前
    不可能,绝对不可能,
    文件名就不允许有斜杠/,
    linux 下文件名 archives/key/month 和路径 archives/key 中的文件 month ,是一个概念,
    will2k
        2
    will2k  
    OP
       266 天前
    解决了,是因为如果 GitHub 仓库中某个文件夹只有一个子文件夹,那么这个文件夹的名称后面就会加个`/`,表示目录分级关系。和 vscode 一样。我没仔细看,以为是文件夹的名称。![image]( https://images.nice2cu.cc/i/2023/08/16/uexsv8.webp)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4957 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 05:35 · PVG 13:35 · LAX 22:35 · JFK 01:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.