Power shell脚本从每个子文件夹中获取数据 [英] Power shell script to get data from each subfolders
本文介绍了Power shell脚本从每个子文件夹中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这个文件夹里有一个文件夹我有大约20个子文件夹,每个子文件夹都有.wav文件,我有一个使用这个脚本的电源shell脚本我可以从一个文件夹中获取数据,但是当我点击主文件夹时,我希望一次性获取所有子文件夹中的数据。下面是我的power shell脚本。请帮我修改我的剧本。
我尝试了什么:
#显示打开文件夹对话框并返回用户选择的目录。
函数Read-FolderBrowserDialog([string] $ Message,[string] $ InitialDirectory,[switch] $ NoNewFolderButton)
{
$ browseForFolderOptions = 0
if($ NoNewFolderButton){ $ browseForFolderOptions + = 512}
$ app = New-Object -ComObject Shell.Application
$ folder = $ app.BrowseForFolder(0,$ Message,$ browseForFolderOptions,$ InitialDirectory)
if($ folder){$ selectedDirectory = $ folder.Self.Path} else {$ selectedDirectory =''}
[System.Runtime.Interopservices.Marshal] :: ReleaseComObject($ app)> $ null
返回$ selectedDirectory
}
$ folder = Read-FolderBrowserDialog
$ com =(New-Object -ComObject Shell.Application).NameSpace($ folder)
for($ i = 0; $ i -lt 64; $ i ++){
$ name = $ com.GetDetailsOf($ com.Items,$ i)
if($ name -eq'Finlength '){$ lengthattribute = $ i}
}
$ com.Items()|
ForEach-Object {
[PSCustomObject] @ {
Name = $ _。Name
Path = $ _。Path
Size = $ com.GetDetailsOf($ _ ,1)
DateCreated = $ com.GetDetailsOf($ _,4)
Length = $ com.GetDetailsOf($ _,$ lengthattribute)
}
} |
Export-csv report.csv -notypeinformation
解决方案
消息,[string]
< blockquote> InitialDirectory,[switch]
NoNewFolderButton)
{
I have a folder inside this folder I have around 20 sub folders, each sub folder having .wav files and I have a power shell script using this script I am able to get data from a single folder, but I want to get data from all sub folders in one go when I click on main folder. Below is my power shell script. Please help me to modify my script.
What I have tried:
# Show an Open Folder Dialog and return the directory selected by the user. function Read-FolderBrowserDialog([string]$Message, [string]$InitialDirectory, [switch]$NoNewFolderButton) { $browseForFolderOptions = 0 if ($NoNewFolderButton) { $browseForFolderOptions += 512 } $app = New-Object -ComObject Shell.Application $folder = $app.BrowseForFolder(0, $Message, $browseForFolderOptions, $InitialDirectory) if ($folder) { $selectedDirectory = $folder.Self.Path } else { $selectedDirectory = '' } [System.Runtime.Interopservices.Marshal]::ReleaseComObject($app) > $null return $selectedDirectory } $folder= Read-FolderBrowserDialog $com = (New-Object -ComObject Shell.Application).NameSpace($folder) for($i = 0; $i -lt 64; $i++) { $name = $com.GetDetailsOf($com.Items, $i) if ($name -eq 'Length') { $lengthattribute = $i} } $com.Items() | ForEach-Object { [PSCustomObject]@{ Name = $_.Name Path = $_.Path Size = $com.GetDetailsOf($_, 1) DateCreated = $com.GetDetailsOf($_, 4) Length = $com.GetDetailsOf($_, $lengthattribute) } } | Export-csv report.csv -notypeinformation
解决方案
Message, [string]
InitialDirectory, [switch]
NoNewFolderButton) {
这篇关于Power shell脚本从每个子文件夹中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文