c# - How do I iterate through a directory stopping at a folder that excludes a specific character? -
i iterate through directory , stop @ first folder doesn't end in "@"
this tried far (based on question site):
string rootpath = "d:\\pending\\engineering\\parts\\3"; string targetpattern = "*@"; string fullpath = directory .enumeratefiles(rootpath, targetpattern, searchoption.alldirectories) .firstordefault(); if (fullpath != null) console.writeline("found " + fullpath); else console.writeline("not found");
i know *@
isn't correct, no idea how part.
i'm having problems searchoption
visual studio says "it's ambiguous reference."
eventually want code name of folder , use rename different folder.
final solution
i ended using combination of dasblikenlight , user3601887
string fullpath = directory .getdirectories(rootpath, "*", system.io.searchoption.topdirectoryonly) .firstordefault(fn => !fn.endswith("@"));
since enumeratefiles
pattern not support regular expressions, need directories, , filtering on c# side:
string fullpath = directory .enumeratefiles(rootpath, "*", searchoption.alldirectories) .firstordefault(fn => !fn.endswith("@"));
Comments
Post a Comment