Use PowerShell to generate a list of files and directories

前端 未结 5 501
予麋鹿
予麋鹿 2021-02-01 15:37

I\'m writing a PowerShell script to make several directories and copy a bunch of files together to \"compile\" some technical documentation. I\'d like to generate a manifest of

5条回答
  •  失恋的感觉
    2021-02-01 16:16

    The following script will show the tree as a window, it can be added to any form present in the script

    function tree {
    
       [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
       [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
    
       # create Window
       $Form = New-Object System.Windows.Forms.Form
       $Form.Text = "Files"
       $Form.Size = New-Object System.Drawing.Size(390, 390)
       # create Treeview-Object
       $TreeView = New-Object System.Windows.Forms.TreeView
       $TreeView.Location = New-Object System.Drawing.Point(48, 12)
       $TreeView.Size = New-Object System.Drawing.Size(290, 322)
       $Form.Controls.Add($TreeView)
    
       ###### Add Nodes to Treeview
       $rootnode = New-Object System.Windows.Forms.TreeNode
       $rootnode.text = "Root"
       $rootnode.name = "Root"
       [void]$TreeView.Nodes.Add($rootnode)
    
       #here i'm going to import the csv file into an array
       $array=@(Get-ChildItem -Path D:\personalWorkspace\node)
       Write-Host $array
       foreach ( $obj in $array ) {                                                                                                             
            Write-Host $obj
            $subnode = New-Object System.Windows.Forms.TreeNode
            $subnode.text = $obj
            [void]$rootnode.Nodes.Add($subnode)
         }
    
       # Show Form // this always needs to be at the bottom of the script!
       $Form.Add_Shown({$Form.Activate()})
       [void] $Form.ShowDialog()
    
       }
       tree
    

提交回复
热议问题