c# - How can I get a single file name by searching for the extension alone? -
c# - How can I get a single file name by searching for the extension alone? -
i'm using c# winforms , want single file name searching extension alone? know directory.getfiles method, i'm looking single file. i'm using...
string[] files = directory.getfiles(@"c:\tpro", "*.fdn"); string test = files.getvalue(0).tostring();
this works name of file ends .fdn. works because file in directory ends .fdn. using index "0" in case works. doesn't sit down me. there improve way go it?
thanks
no; sane way it. however, you're misusing array; should write string test = files[0]
.
in .net 4.0, can utilize iterator version avoid fetching more files needed:
ienumerable<string> files = directory.enumeratefiles(@"c:\tpro", "*.fdn"); string test = files.first();
this much faster enormous directories.
c# file-io filesystems
Comments
Post a Comment