更新时间:2022-10-15 11:50:34
你试过这个: system.io .path.getextension [ ^ ]
尝试:string path = @ D:\ Sam \DSC0001;
int index = path.LastIndexOf(' \\'跨度>);
if (index > 0 )
{
string dir = path.Substring( 0 ,index );
string file = path.Substring(index + 1 );
string [] files = Directory.GetFiles(dir,file + *跨度>)。
if (files.Length > 0 )
{
// 文件存在。
foreach (字符串 f 在文件中)
{
Console.WriteLine(Path.GetExtension(f));
}
}
}
Dim path_ as string = D:\DSC0001
Dim fileExtension 作为 字符串 = Path.GetExtension(path_)
如果 不 File.Exists(file_path& 。& fileExtension)然后
msgbox( 找不到文件)
结束 如果
can i get extension from file name
my file is
D:\Sam\DSC0001
now i want to check DSC0001 extension and file exist or not
please help me
:-)
Have you tried this : system.io.path.getextension[^]
Try:string path = @"D:\Sam\DSC0001"; int index = path.LastIndexOf('\\'); if (index > 0) { string dir = path.Substring(0, index); string file = path.Substring(index + 1); string[] files = Directory.GetFiles(dir, file + ".*"); if (files.Length > 0) { // File exists. foreach (string f in files) { Console.WriteLine(Path.GetExtension(f)); } } }
Dim path_ as string = "D:\DSC0001" Dim fileExtension As String = Path.GetExtension(path_ ) If Not File.Exists(file_path & "." & fileExtension) Then msgbox("File Not Found") End If