textbox从路径获取文件名 [英] textbox get filename from path
本文介绍了textbox从路径获取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
i想在c#中创建一个文本框并自动从我给出的路径中获取文件名。
谢谢
Hello
i want to make a text box in c# and automatic get the filename from path that i gave.
thanks
推荐答案
尝试:
Try:
string pathToFile = @"D:\Temp\Myfile.txt";
string justTheFileName = Path.GetFileNameWithoutExtension(pathToFile); // MyFile
string justTheFileNameWithExtension = Path.GetFileName(pathToFile); // MyFile.txt
string justTheExtension = Path.GetExtension(pathToFile); // .txt
string justThefolderItsIn = Path.GetDirectoryName(pathToFile); // D:\Temp
String path=@"C:\Program Files\Test.txt";
MessageBox.Show(Path.GetFileName(path));
结果将是Test.txt
result will be "Test.txt"
这篇关于textbox从路径获取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文