You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After reading #3349 a bit I came up with the following "helper" :
internal DirectoryPath GetParent(DirectoryPathpath){path= MakeAbsolute(path);// to be sure. I's no use splitting the segments of "."if(path.Segments.Length ==1){// one segment on Windows is e.g. "C:/" // on all other systems one segment is e.g "/home"if(IsRunningOnWindows()){// no more parentsreturnnull;}else{// root ("/") is not really a segment for Cake, // so we return that directly.returnnew DirectoryPath("/");}}if(path.Segments.Length ==0){returnnull;}varsegments= path.Segments.Take(path.Segments.Length -1);returnnew DirectoryPath(string.Join(path.Separator.ToString(), segments));}
the code from above then changes:
[...]
var parent = GetParent(dir);if(parent==null){[...]
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I want to walk a folder structure "up". I.e. given a folder I want to check it's parent, then that parent and so on. Until I found the root ..
Given the following script:
on windows the output looks something like:
and on linux the output is something like:
Of cause I could walk
System.IO.Path.GetDirectoryName()
until the result isnull
, but that's not very Cake, is it?Beta Was this translation helpful? Give feedback.
All reactions