c# - Adjusted output for looping through a directory -
i have bit of code directed loop through directory , display results in listbox. have working, output displays entire file path (\server\directory\directory\subdirectory\filename.filetype) in listbox. ideally, display filename , filetype (ie. workbook1.xlsm).
string[] filepaths = directory.getfiles(@"\\server\directory\folder\folder\", "*.xlsm", searchoption.alldirectories); statuscodelb.items.clear(); foreach (string file in filepaths) { statuscodelb.items.add(file); } statuslabel.text = statuscodelb.items.count.tostring();
also, there way functional on mac os x (10.6 , 10.7 precise)?
i have working, output displays entire file path (\server\directory\directory\subdirectory\filename.filetype) in listbox. ideally, display filename , filetype (ie. workbook1.xlsm).
you looking path.getfilename(path)
, documented here. documentation reads follows:
returns file name , extension of specified path string.
string[] filepaths = directory.getfiles(@"\\server\directory\folder\folder\", "*.xlsm", searchoption.alldirectories); statuscodelb.items.clear(); foreach (string file in filepaths) { statuscodelb.items.add(path.getfilename(file)); } statuslabel.text = statuscodelb.items.count.tostring();
if file (input) "c:\some\directory\structure\filename.ext"
resulting string added listbox.items
(output) filename.ext
.
Comments
Post a Comment