Use PowerShell to generate a list of files and directories

前端 未结 5 493
予麋鹿
予麋鹿 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:06

    In your particular case what you want is Tree /f. You have a comment asking how to strip out the part at the front talking about the volume, serial number, and drive letter. That is possible filtering the output before you send it to file.

    $Path = "C:\temp"
    Tree $Path /F | Select-Object -Skip 2 | Set-Content C:\temp\output.tkt
    

    Tree's output in the above example is a System.Array which we can manipulate. Select-Object -Skip 2 will remove the first 2 lines containing that data. Also, If Keith Hill was around he would also recommend the PowerShell Community Extensions(PSCX) that contain the cmdlet Show-Tree. Download from here if you are curious. Lots of powerful stuff there.

提交回复
热议问题