如何从路径获取文件名? [英] How to get the file name from path?

查看:185
本文介绍了如何从路径获取文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助来获取没有完整路径的文件名是我所做的代码但是没有用。请帮助。

Hi, i need help to get the file name without the full path here is the code i did but is not working.Please help.

filelist.Items.Clear()
              Dim fileinformation As FileInfo
              For Each files In Directory.GetFiles(path)
                  fileinformation = files
                  filelist.Items.Add(fileinformation.Name)
              Next





我尝试了什么:



这个不起作用但是这个一个是



What I have tried:

well this one doesn't work but this one does

 filelist.Items.Clear()
 For Each files In Directory.GetFiles(path)
   filelist.Items.Add(files
Next

推荐答案

Path.GetFileName Method(System.IO) [ ^ ]



给这个方法提供完全限定的路径,它只给你文件名部分。
Path.GetFileName Method (System.IO)[^]

Give this method the fully qualified path and it'll give you just the filename portion.


filelist.Items.Clear()
Dim fileinformation As FileInfo
For Each files In Directory.GetFiles(path)
	fileinformation = files
	filelist.Items.Add(fileinformation.Name.ToString.Replace(fileinformation.extension,"").Trim)
Next


这篇关于如何从路径获取文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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