当我在文件上使用 e.Fullname
或 e.Name
时,它会给我全名 + 扩展名,但我只想要文件名而不用像:名字后面的“.txt”。
如何只显示文件名而不显示其后的扩展名?是否有特定的代码?
我是否必须从 e.fullname
中获取扩展名,只使用保留的部分作为没有扩展名的名称?我应该做其中的哪一项?
像这样:
private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
{
listBox1.Items.Add("File changed> " + e.FullPath + " -Date:" + DateTime.Now);
name = e.Name;
extension = Path.GetExtension(e.FullPath);
size = e.Name.Length;
}
最佳答案
System.IO.Path
有一个 GetFileNameWithoutExtension
听起来像您正在寻找的方法:
Returns the file name of the specified path string without the extension.
关于C# e.Fullname 没有扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17399345/