0

I want to remove the space/ area taken up in showing the

Directory: C:\Users\varun\Desktop\Projects\advanced-react-patterns-v2

when I run the command:

Get-ChildItem | Format-Wide

screenshot]

Additional details:

  • Using Windows Terminal & Powershell
  • Font used in the screenshot: TerminessTTF NF
  • Used Terminal-Icons

Note: The command

Get-ChildItem -Name

failed to show the terminal icons which kind of my main goal here.

enter image description here

varunswarup0
  • 23
  • 1
  • 1
  • 6

1 Answers1

1

When you are using a Format-* command you are using the default formatting output for the File and Directory objects, which groups files by directory - hence the directory name at the top.

If you wanted to by pass this, you would have to write your own format.ps1xml file and then add the formatting to your output.

$files = Get-ChildItem
foreach ($file in $files) {
    $file.PSObject.TypeNames.Insert(0,'Custom.Output.Type')
    $file
}

Small sample of XML for the specified Typename, customise as you wish.

<View>
    <Name>CustomFileFormatting</Name>
    <ViewSelectedBy>
        <TypeName>Custom.Output.Type</TypeName>
    </ViewSelectedBy>
    <TableControl>
        <AutoSize />
        <TableHeaders>
            <TableColumnHeader>
                <Label>FullName</Label>
                <Alignment>Left</Alignment>
            </TableColumnHeader>
        </TableHeaders>
        <TableRowEntries>
            <TableRowEntry>
                <TableColumnItems>
                    <TableColumnItem>
                        <PropertyName>FSObject</PropertyName>
                    </TableColumnItem>
                </TableColumnItems>
            </TableRowEntry>
        </TableRowEntries>
    </TableControl>
</View>
Ash
  • 3,030
  • 3
  • 15
  • 33
  • Tried to create fromat.ps1xml, received the following error: 'c:\Windows\System32\WindowsPowerShell\v1.0\format.ps1xml' (NoPermissions (FileSystemError): Error: EPERM: operation not permitted, open 'c:\Windows\System32\WindowsPowerShell\v1.0\format.ps1xml') – varunswarup0 Apr 28 '20 at 08:58
  • I would create it in a user directory where your script is. Please follow the information in the link I provided on how to use the formatting data. – Ash Apr 28 '20 at 09:42
  • I have created /Mygciview.Format.ps1xml as specified in the link and put it in my project folder. – varunswarup0 Apr 28 '20 at 18:39
  • Then I made a custom power shell function as follow: function Format-TC { $files = Get-ChildItem foreach ($file in $files) { $file.PSObject.TypeNames.Insert(0,'Mygciview.Format.ps1xml') # $file }} – varunswarup0 Apr 28 '20 at 18:40
  • You do not use the name of the XML in the insert statement, you use the TypeName. Please follow the linked documentation. It does work. – Ash Apr 29 '20 at 09:33