简体   繁体   English

Go 使用 \.. 在字符串路径中向上一个目录 - Python os.path

[英]Go up a directory using \.. in string path - Python os.path

I'm writing a post-job script for Thinkbox Deadline.我正在为 Thinkbox Deadline 编写一份工作后脚本。 I need the directory for the rendered frames from a finished Cinema 4D job.我需要完成 Cinema 4D 作业的渲染帧的目录。

In Cinema, we had the frames know to go up a few directories, then back down to a different location by using this syntax "path\to\c4d_file....\renders\frame_00.png"在 Cinema 中,我们让 go 知道的帧在几个目录中,然后使用此语法“path\to\c4d_file....\renders\frame_00.png”返回到不同的位置

In this example the ".." tells Cinema to go up 2 folders to the "path" folder then back down into the "renders" folder where it saves the renders to.在此示例中,“..”告诉 Cinema go 向上 2 个文件夹到“path”文件夹,然后返回到“renders”文件夹,将渲染保存到该文件夹。

Unfortunately Deadline doesn't calculate the actual path when it makes the render job.不幸的是,截止日期在进行渲染作业时不会计算实际路径。 When I tell the post-job script to go to the path location, it doesn't understand the '..' -- so I need to tell it where to go up a directory and where to go back down.当我将作业后脚本告诉 go 到路径位置时,它不理解“..”——所以我需要告诉它 go 到目录的位置以及 Z34D1F91FB2E514B857BZFAB1 的位置。

Is there any sort of Python magic that can basically read the ".." and know how to make the correct directory?是否有任何类型的 Python 魔法基本上可以读取“..”并知道如何制作正确的目录?

Thanks谢谢

Take the absolute path and remove the last one取绝对路径,去掉最后一个

path.sep.join(path.abspath('.').split(path.sep)[:-1])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM