小编Yoo*_*kim的帖子

如何使用多个条件过滤Directory.EnumerateFiles?

我有以下代码:

List<string> result = new List<string>();

foreach (string file in Directory.EnumerateFiles(path,"*.*",  
      SearchOption.AllDirectories)
      .Where(s => s.EndsWith(".mp3") || s.EndsWith(".wma")))
       {
          result.Add(file);                 
       }
Run Code Online (Sandbox Code Playgroud)

它工作正常,做我需要的.除了一件小事.我想找到一种更好的方法来过滤多个扩展.我想使用带有过滤器的字符串数组,例如:

string[] extensions = { "*.mp3", "*.wma", "*.mp4", "*.wav" };
Run Code Online (Sandbox Code Playgroud)

使用.NET Framework 4.0/LINQ执行此操作的最有效方法是什么?有什么建议?

我很感激任何帮助成为偶尔的程序员:-)

.net c#

72
推荐指数
6
解决办法
7万
查看次数

使用PowerShell 2.0将多个XML文件合并为一个?

我有一个非常大的XML文件目录,结构如下:

file1.xml:

<root>
 <EmployeeInfo attr="one" />
 <EmployeeInfo attr="two" />
 <EmployeeInfo attr="three" />
</root>
Run Code Online (Sandbox Code Playgroud)

file2.xml:

<root>
 <EmployeeInfo attr="four" />
 <EmployeeInfo attr="five" />
 <EmployeeInfo attr="six" />
</root>
Run Code Online (Sandbox Code Playgroud)

现在我正在寻找一种将这些文件(*.xml)文件合并到一个输出文件中的简单方法:

<root>
 <EmployeeInfo attr="one" />
 <EmployeeInfo attr="two" />
 <EmployeeInfo attr="three" />
 <EmployeeInfo attr="four" />
 <EmployeeInfo attr="five" />
 <EmployeeInfo attr="six" />
</root>
Run Code Online (Sandbox Code Playgroud)

我正在考虑使用像这样的纯XSLT:

<xsl:transform version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <Container>
      <xsl:copy-of select="document('file1.xml')"/>
      <xsl:copy-of select="document('file2.xml')"/>        
    </Container>
  </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

这有效,但不如我想要的那么灵活.作为PowerShell(第2版)的新手,渴望学习在PowerShell中使用XML的新的最佳实践,我想知道什么是将XML文档结构合并为一个最简单,最纯粹的PowerShell方法

干杯,Joakim

xml powershell powershell-2.0

6
推荐指数
1
解决办法
2万
查看次数

Azure cmdlet - 使用双因素身份验证时会话无效

我管理了很多Azure订阅并经常使用Get-AzureSubscription来列出我有权访问的订阅.

最近我在我的帐户中添加了双因素身份验证.现在我得到一些命令的奇怪错误.我可以使用Add-AzureAccount登录,但是当我尝试列出订阅时,我收到错误"Get-AzureSubscription : AADSTS16000: Session is invalid due to expiration or recent password change.

有没有人见过这个?我很欣赏任何想法如何规避这一点.

这是我做的:

PS C:\ > add-azureaccount

Id                             Type       Subscriptions                          Tenants
--                             ----       -------------                          -------
username@domain.com            User       xxxxxx-yyyyyy   xxxxxx-yyyyyy
                                          xxxxxx-yyyyyy
                                          xxxxxx-yyyyyy
                                          xxxxxx-yyyyyy
                                          xxxxxx-yyyyyy
                                          xxxxxx-yyyyyy
                                          xxxxxx-yyyyyy


    PS C:\ > Set-AzureSubscription -SubscriptionId 'xxxxxx-yyyyyy'
    PS C:\ > select-AzureSubscription -SubscriptionId 'xxxxxx-yyyyyy'
    PS C:\ > Get-AzureSubscription -ExtendedDetails
    Get-AzureSubscription : AADSTS16000: Session is invalid due to expiration or recent password change.
    Trace ID: 6fcfa2da-7d7a-43ba-8230-a227312b535b
    Correlation ID: 7206fefd-29fa-4103-ba4f-eb15350a0754
    Timestamp: 2015-04-01 17:57:28Z
    At line:1 …
Run Code Online (Sandbox Code Playgroud)

powershell azure

6
推荐指数
1
解决办法
553
查看次数

标签 统计

powershell ×2

.net ×1

azure ×1

c# ×1

powershell-2.0 ×1

xml ×1