擅长:python、mysql、java
<p>您的<code>logfilepath</code>是<code>\Logs\LogMain.log</code>,这是绝对路径(没有驱动器),不是相对路径,而不仅仅是文件名-因此它不会像您期望的那样加入</p>
<p>当您尝试加入绝对路径时,它只保留驱动器并替换以前的绝对路径</p>
<p>您只需从<code>\Logs\LogMain.log</code>-ie获取<code>filename</code></p>
<pre><code> logfilepath.split('\\')[-1]
</code></pre>
<p>只有<code>LogMain.log</code>并最终获得</p>
<pre><code> C:\Users\abc\Downloads\directory\LogMain.log
</code></pre>
<hr/>
<pre><code>folder = os.path.abspath(os.getcwd())
logfilepath = GetServiceConfigData.getConfigData('logfilepath')
filename = logfilepath.split('\\')[-1]
os.path.join(folder, filename)
</code></pre>
<hr/>
<p><strong>编辑</strong></p>
<p>如果<code>logfilepath</code>类似于对象<code>pathlib.Path</code></p>
<pre><code>from pathlib import Path
p = Path('\Logs\LogMain.log')
</code></pre>
<p>然后,您可以使用</p>
<pre><code>p.name
</code></pre>