简体   繁体   English

Powershell脚本获取目录树的全名

[英]Powershell script to get FullName of a Directory tree

I'm trying to get an output of the FullName of a Folder of each level from a specific directory tree. 我正在尝试从特定目录树中获取每个级别的文件夹的FullName的输出。

I want to get an output like: 我想得到类似的输出:

C:\
C:\dir1
C:\dir1\dir2
C:\dir1\dir2\dir3

The thing is that the directory has to be specific... like the directory part between C:\\ and C:\\dir1\\dir2\\dir3 问题是目录必须是特定的...就像C:\\C:\\dir1\\dir2\\dir3之间的目录部分一样

Like a start path and end path, any thoughts? 像开始路径和结束路径一样,您有什么想法吗?

For PowerShell v3 or later: 对于PowerShell v3或更高版本:

Get-ChildItem C:\dir1 -Directory -Recurse |
  Select-Object -ExpandProperty FullName

For older versions: 对于旧版本:

Get-ChildItem C:\Dir1 -Recurse |
  Where-Object { $_.PSIsContainer } |
  Select-Object -ExpandProperty FullName

Try this: 尝试这个:

$Path = 'C:\dir1\dir2\dir3'

$Folders = $Path -Split "\\"
$Folders | % { $i = 0 } { $Folders[0..$i] -Join "\" -Replace ":$", ":\"; $i++ } 

Result: 结果:

C:\
C:\dir1
C:\dir1\dir2
C:\dir1\dir2\dir3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM