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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -