擅长:python、mysql、java
<p>如果您只是希望文件名本身不带<code>path</code>:</p>
<pre><code>sorted_files = sorted(os.path.basename(f) for f in files)
</code></pre>
<p>如果希望仅按文件名排序,而不按扩展名排序:</p>
<pre><code>sorted_files = sorted([os.path.basename(f) for f in files], key=lambda x: os.path.splitext(x)[0])
</code></pre>
<p>尽管如此,对于相同的<code>path</code>和扩展,我不理解这样做的必要性。排序本身应该可以工作:<code>sorted(files)</code></p>