[英]Built-in function or Cmdlets to store all folders names in an array in PowerShell
I have found an answer of how to store the folders names of the current folder in an array.我找到了如何将当前文件夹的文件夹名称存储在数组中的答案。 by @Shay Levy - The Solution - Storing Directory Folder Names Into Array Powershell .
@Shay Levy - 解决方案 - 将目录文件夹名称存储到数组 Powershell中。 So is there anything built-in within PowerShell that do this process.
那么PowerShell中是否有任何内置的东西可以完成这个过程。 as the variable will be used in another function later.
因为该变量稍后将在另一个函数中使用。
The solution I found:我找到的解决方案:
$arr = Get-ChildItem \\QNAP\wpbackup | Where-Object {$_.PSIsContainer} | Foreach-Object {$_.Name}
I think you want to use every single element in array for other scopes:我认为您想将数组中的每个元素用于其他范围:
$wDir = '\\QNAP\wpbackup'
$arr = Get-ChildItem -Directory -Name -Path $wDir
Another solution:另一种解决方案:
$wDir = '\\QNAP\wpbackup'
$arr = @(Get-ChildItem -Directory -Name -Path $wDir)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.