Windows路径上的path.dirname给`。 [英] path.dirname on Windows path is giving `.`

查看:258
本文介绍了Windows路径上的path.dirname给`。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做电子:

 path.dirname('C:\\Users\\Blagoh\\Documents\\GitHub\\Screeenshoter\\dist\\electron\\main')

该路径是我的 __ dirname 的实际值。它怎么不给我 C:\\Users\\Blagoh\\Documents\\GitHub\\Screeenshoter\\dist\\electron ?我希望将主要部分切掉。

That path is the actual value of my __dirname. How come it is not giving me C:\\Users\\Blagoh\\Documents\\GitHub\\Screeenshoter\\dist\\electron? I want that main part chopped off.

推荐答案

好吧,您显然没有尚未阅读 dirname 的文档。它说它像Unix命令 dirname 一样工作,它从文件名中去除非目录后缀,因此得到 C:\\ \用户\\Blagoh\\文档\\GitHub\\Screeenshoter\\dist\\electron

Well you obviously didn't read the docs for dirname. It states that it works like the Unix command dirname which "strips non-directory suffix from file name", thus you get the C:\\Users\\Blagoh\\Documents\\GitHub\\Screeenshoter\\dist\\electron.

您要查找的是基本名称

path.basename('C:\\Users\\Blagoh\\Documents\\GitHub\\Screeenshoter\ \dist\\electron\\main')会给您 main

这篇关于Windows路径上的path.dirname给`。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆