简体   繁体   English

用于将所有文件夹名称存储在 PowerShell 中的数组中的内置函数或 Cmdlet

[英]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.

相关问题 有没有办法查看内置PowerShell cmdlet的源代码? - Is there any way to view the source for built-in powershell cmdlets? Powershell - 复制名称与数组匹配的文件夹 - Powershell - Copy folders with names matching array PowerShell cmdlet中的计算机名称和dnshostname之间的区别? - Difference between computer names and dnshostname in PowerShell cmdlets? 如何在powershell中列出所有已安装、可运行的cmdlet? - How to list all installed, runnable cmdlets in powershell? Powershell-命名参数和脚本内置函数? - Powershell - named parameters and script built-in functions? Powershell,内置的交叉设置? - Powershell, kind of set intersection built-in? Teamcity无法使用Powershell打印内置参数 - Teamcity not printing built-in parameters using Powershell 在执行内置cmdlet之后,有条件地执行自定义Powershell函数/ cmdlet - Conditionally execute custom powershell function/cmdlet after a built-in cmdlet is executed 如何使用Powershell获取文件夹中所有文件夹名称而不是子文件夹中文件/子文件夹的.txt文件? - How to get a .txt file of all folders names inside a folder but not the files/subfolders inside the child folders using powershell? 在 powershell 中导入 Posh-ssh 模块不会导入所有 cmdlet - Importing Posh-ssh moudle in powershell does not import all cmdlets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM