{"id":2078,"date":"2016-11-18T07:44:10","date_gmt":"2016-11-18T13:44:10","guid":{"rendered":"https:\/\/www.wiredprairie.us\/blog\/?p=2078"},"modified":"2016-11-18T09:17:10","modified_gmt":"2016-11-18T15:17:10","slug":"tree-console-app-in-go","status":"publish","type":"post","link":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/2078","title":{"rendered":"Tree walking and display console app in Go"},"content":{"rendered":"

I hadn\u2019t done anything at all interesting in Go. And some might say, I still haven\u2019t. However, I wanted to do something that I\u2019d find occasionally useful.<\/p>\n

On Linux, this is already available, but the the Windows version is lacking. I wanted a tiny console app that would display a tree of the directory and file structure.<\/p>\n

So, that\u2019s what I built. \"Smile\"<\/p>\n

It\u2019s one small file with one external library dependency.<\/p>\n

I did notice that the Go packages for\u00a0directory scanning like ReadDir\u00a0<\/strong>suffer from a common issue when using the traditional Win32 APIs: they do not adequately handle file paths longer than about 250 characters. When you have NodeJS source code on your system with lots of deeply nested paths, many Windows programs fail miserably when doing file\/folder management operations (Windows Explorer, I’m looking at YOU<\/strong>).\u00a0Using the one “easy” trick<\/em> of prepending the path with \\\\?\\<\/strong>, you can use the APIs like ReadDir reasonably reliably. Whereas in earlier versions of my tree app it would crash, it now can handle deeply nested directory structures.<\/p>\n

\"image\"<\/a><\/p>\n

go get\u00a0github.com\/fatih\/color<\/pre>\n