5

The following input:

PS STG:\> Get-ChildItem | tree

Gives me

Folder PATH listing for volume Data
Volume serial number is 6576-C540
D:.
ÃÄÄÄAPK
ÃÄÄÄAssets
³   ÃÄÄÄAnimations
³   ³   ÃÄÄÄCharacters
³   ³   ³   ÀÄÄÄinhabitant
³   ³   ÃÄÄÄEnvironment
³   ³   ÀÄÄÄProps
³   ÃÄÄÄMaterials
³   ³   ÃÄÄÄCharacters
³   ³   ³   ÀÄÄÄinhabitant
³   ³   ÃÄÄÄEnvironment
³   ³   ÃÄÄÄParticles
³   ³   ³   ÀÄÄÄasteroidParticle
³   ³   ÀÄÄÄProps
³   ÃÄÄÄMeshes
³   ³   ÃÄÄÄCharacters
³   ³   ³   ÀÄÄÄinhabitant
³   ³   ÃÄÄÄEnvironment
³   ³   ÀÄÄÄProps

...etc.

When I was expecting something formatted more like:

├───APK
├───Assets
    └───Animations
    |   └───Characters
    |   |   └───inhabitant
    |   ├───Environment
    |   └───Props
    └───Materials
    |   └───Characters
    |   |   └───inhabitant
    |   ├───Environment
    |   └───Particles
    |   |   └───asteroidParticle
    |   └───Props
    └───Meshes
        └───Characters
        |   └───inhabitant
        ├───Environment
        └───Props

What am I doing / understanding wrong?

This is the value of $OutputEncoding:

IsSingleByte      : True
BodyName          : iso-8859-1
EncodingName      : Western European (Windows)
HeaderName        : Windows-1252
WebName           : Windows-1252
WindowsCodePage   : 1252
IsBrowserDisplay  : True
IsBrowserSave     : True
IsMailNewsDisplay : True
IsMailNewsSave    : True
EncoderFallback   : System.Text.InternalEncoderBestFitFallback
DecoderFallback   : System.Text.InternalDecoderBestFitFallback
IsReadOnly        : True
CodePage          : 1252`
  • in powershell type $OutputEncoding and paste the results – Keltari Apr 23 '14 at 14:30
  • See edit in post. – aPerfectMisterMan Apr 23 '14 at 14:34
  • @MHA, please copy the detail into your original post - the post can be edited. – Dave Apr 23 '14 at 14:36
  • It definitely looks like an encoding problem. My tree works and the encoding is us-ascii. IsSingleByte : True BodyName : us-ascii EncodingName : US-ASCII HeaderName : us-ascii WebName : us-ascii WindowsCodePage : 1252 IsBrowserDisplay : False IsBrowserSave : False IsMailNewsDisplay : True IsMailNewsSave : True EncoderFallback : System.Text.EncoderReplacementFallback DecoderFallback : System.Text.DecoderReplacementFallback IsReadOnly : True CodePage : 20127 – Keltari Apr 23 '14 at 14:40
  • 1
    @MHA Does using the ascii switch for tree help? gci| tree /A – Rynant Apr 24 '14 at 14:40
0

Try using the Show-Tree commandlet.

09:17 $ Show-Tree C:\Chocolatey\ -Depth 1
C:\Chocolatey\
|--bin
\--lib
0

Depending on the version of PowerShell and the presence or absence of community extensions, you can actually end up calling C:\Windows\System32\tree.com. The gibberish is because PowerShell is not using the correct encoding to display the extended characters that tree.com uses by default. You can use chcp.com to see what the command processor's current code page setting is. The usual default is code page 437. PowerShell uses code page 1252 by default. There are to options for dealing with this that work well and are both low-impact and simple.

  1. Just use tree '/A'.
  2. Convert the output from tree to bytes and load it with the proper code page using the following code:

tree | %{ [System.Text.Encoding]::GetEncoding('IBM437').GetString($OutputEncoding.GetBytes($_)) }

-1

Are you running the command in Powershell or Powershell ISE?

There's a difference.

This is what I get in Powershell ISE:

PS C:\powershell> Get-ChildItem | tree
Folder PATH listing
Volume serial number is XXXX-XXXX
C:.
ÃÄÄÄFolder 1
³   ÃÄÄÄSubfolder 1
³   ÃÄÄÄSubfolder 2
³   ÃÄÄÄSubfolder 3
³   ÀÄÄÄSubfolder 4
ÃÄÄÄFolder 2
³   ÃÄÄÄSubfolder 1
³   ÃÄÄÄSubfolder 2
³   ÃÄÄÄSubfolder 3
³   ÀÄÄÄSubfolder 4
ÃÄÄÄFolder 3
³   ÃÄÄÄSubfolder 1
³   ÃÄÄÄSubfolder 2
³   ÃÄÄÄSubfolder 3
³   ÀÄÄÄSubfolder 4
ÀÄÄÄFolder 4
    ÃÄÄÄSubfolder 1
    ÃÄÄÄSubfolder 2
    ÃÄÄÄSubfolder 3
    ÀÄÄÄSubfolder 4

PS C:\powershell> 

This is what I get in Powershell:

PS C:\powershell> Get-childitem | tree
Folder PATH listing
Volume serial number is XXXX-XXXX
C:.
+---Folder 1
¦   +---Subfolder 1
¦   +---Subfolder 2
¦   +---Subfolder 3
¦   +---Subfolder 4
+---Folder 2
¦   +---Subfolder 1
¦   +---Subfolder 2
¦   +---Subfolder 3
¦   +---Subfolder 4
+---Folder 3
¦   +---Subfolder 1
¦   +---Subfolder 2
¦   +---Subfolder 3
¦   +---Subfolder 4
+---Folder 4
    +---Subfolder 1
    +---Subfolder 2
    +---Subfolder 3
    +---Subfolder 4

PS C:\powershell>
  • Interesting point here, but I must say my experience differs - tree output is the same regardless of using console or ISE. Do you have the community extensions installed, or is this using CMD's tree? – Iszi Oct 15 '14 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.