如何获得所选文件夹的名称?
问题描述:
我在Windows资源管理器的文件夹的上下文菜单中添加了一个新项"ADD".
通过右键单击一个文件夹并在上下文菜单中选择添加",必须读取该文件夹中的所有文件.为此,我需要知道刚刚在资源管理器中选择的文件夹的名称.
右键单击上下文菜单时,如何检索文件夹的名称?
I have added a new item ''ADD'' in Context Menu of folder in Windows Explorer.
By right click a folder and select ADD in the context menu, all files in the folder have to be read. For this, I need to know the name of the folder just selected in the explorer.
How can I retrieve the name of the folder when I right click the context menu?
答
如果使用Path.GetFilename,它将实际上从目录中返回目录名称.完整的路径传递到其中.
If you use Path.GetFilename, it will actualy return the directory name from the full path passed into it.
我检索到的路径没有文件夹的名称.如果我在路径C:\ Files中选择了一个名为"Debug"的文件夹,它将仅检索C:\ Files.因此,Path.GetFileName(c:\ Files)给我"Files"作为我的文件夹名称.但是我需要使用"Debug"作为文件夹名称或将C:\ Files \ Debug作为CurrentDirectory.
The path I have retrieved doesn''t have the name of the folder. If I selected a Folder named ''Debug'' in the path C:\Files , it will retrieve only C:\Files. Thus Path.GetFileName(c:\Files) give me ''Files'' as name of my folder. But I needed ''Debug'' as the folder name or C:\Files\Debug as CurrentDirectory.
也许您想要做的是获取应用程序的路径exe,而不是当前目录?
顺便说一下,请编辑您的帖子,不要发布虚假答案,这只会使论坛难以阅读.
Perhaps what you want to do, is get the path to your application''s exe, instead of the current directory ?
By the way, PLEASE edit your post, don''t post fake answers, it just makes the forums hard to read.