@@ -111,19 +111,24 @@ private static async Task<long> GetDirectorySizeAsync(DirectoryInfo directoryInf
111111
112112 private static void PrintDirectory ( string directory , long directorySize , List < FileObject > fileObjects )
113113 {
114- int sizeIndent = fileObjects . Max ( x => x . Name . Length ) + 5 ;
114+ int sizeIndent = Math . Max ( fileObjects . Max ( x => x . Name . Length ) , directory . Length ) + 5 ;
115115
116- string directoryName = $ "{ ConsoleColors . Blue } { directory . PadRight ( sizeIndent ) } ";
116+ string directoryName = $ "{ ConsoleColors . Blue } { directory } { ConsoleColors . Reset } ";
117117 string directorySizeText = $ "{ ConsoleColors . Yellow } { Utils . GetSizeText ( directorySize ) } ";
118- Console . WriteLine ( $ "{ ConsoleSymbols . Folder } { directoryName } { directorySizeText } { ConsoleColors . Reset } ") ;
119-
120- foreach ( FileObject fileObj in fileObjects )
118+ int lineLength = sizeIndent - directoryName . Length + 10 ;
119+ string line = new string ( ConsoleSymbols . Line [ 0 ] , lineLength ) ;
120+ Console . WriteLine ( $ "{ ConsoleSymbols . Folder } { directoryName } { line } { directorySizeText } { ConsoleColors . Reset } ") ;
121+
122+ for ( int i = 0 ; i < fileObjects . Count ; i ++ )
121123 {
122- string icon = fileObj . IsDirectory ? ConsoleSymbols . Folder : ConsoleSymbols . File ;
123- string fileName = $ "{ ConsoleColors . Cyan } { fileObj . Name . PadRight ( sizeIndent ) } ";
124- string fileSize = $ "{ ConsoleColors . Yellow } { Utils . GetSizeText ( fileObj . SizeInBytes ) } ";
124+ FileObject fileObject = fileObjects [ i ] ;
125+
126+ string treeSymbol = i == fileObjects . Count - 1 ? ConsoleSymbols . TreeEnd : ConsoleSymbols . TreeBranch ;
127+ string icon = fileObject . IsDirectory ? ConsoleSymbols . Folder : ConsoleSymbols . File ;
128+ string fileName = $ "{ ConsoleColors . Cyan } { fileObject . Name . PadRight ( sizeIndent - treeSymbol . Length - 1 ) } ";
129+ string fileSize = $ "{ ConsoleColors . Yellow } { Utils . GetSizeText ( fileObject . SizeInBytes ) } ";
125130
126- Console . WriteLine ( $ "{ icon } { fileName } { fileSize } { ConsoleColors . Reset } ") ;
131+ Console . WriteLine ( $ "{ treeSymbol } { icon } { fileName } { fileSize } { ConsoleColors . Reset } ") ;
127132 }
128133 }
129134}
0 commit comments