Get the file extension without providing the extension in the path

Is it possible to get the file extension, but when you specify the whole path other than the extension? For instance:

C: \ Users \ Administrator \ Pictures \ BlueHillsTest

thank

+5
source share
2 answers

Directory.GetFiles allows you to specify a template for searching files:

System.IO.Directory.GetFiles(@"C:\temp\py\", "test.*")

for me returns an array of 3 matching elements. I expect an array as the directory contains test.cover, test.pyand test.pyc.

If I use the extension method First:

System.IO.Directory.GetFiles(@"C:\temp\py\", "test.*").First()

then it returns only the first result ( test.cover).

However, using the extension method Single:

System.IO.Directory.GetFiles(@"C:\temp\py\", "test.*").Single()

InvalidOperationException, " " ( , , ).

System.IO.Directory.GetFiles(@"C:\temp\py\", "step.*").Single()

step.py ( ), , step.* .

+13

, , BlueHillsTest.xxx, BlueHillsTest.yyy. ?

+2

All Articles