How do I get the full path of the current file's directory?

前端 未结 15 1093
傲寒
傲寒 2020-11-22 17:01

I want to get the current file\'s directory path. I tried:

>>> os.path.abspath(__file__)
\'C:\\\\python27\\\\test.py\'

But how can

15条回答
  •  执笔经年
    2020-11-22 17:24

    Let's assume you have the following directory structure: -

    main/ fold1 fold2 fold3...

    folders = glob.glob("main/fold*")
    
    for fold in folders:
        abspath = os.path.dirname(os.path.abspath(fold))
        fullpath = os.path.join(abspath, sch)
        print(fullpath)
    

提交回复
热议问题