获取文件夹中的所有文件,包括那些具有长(> 256 个字符)路径 + 名称的文件 [英] Get all files in folder including those with long (>256 characters) path + name

查看:51
本文介绍了获取文件夹中的所有文件,包括那些具有长(> 256 个字符)路径 + 名称的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在特定文件夹中构建一个逗号分隔的文件名列表.这些文件的名称往往很长(它们是测试用例结果,名称非常具有描述性).

I'm trying to build a comma separated list of file names in a specific folder. These files tend to have long names (they're test case results and the name is very descriptive).

我发现 Get-ChildItem 会忽略名称(包括路径)太长的文件.

I've found that Get-ChildItem ignores files whose name (including path) is too long.

# Folder contains the following file (240 chars, actual name is 'only' 210 chars):
# SomeServiceWithAnAlreadyLongNameUnderTest_NameOfTheParticularTestSuiteThatProducedThisResult-NameOfTheActualMethodUnderTest-Given_A_Certain_Precondition_Is_Met_WhenCalling_With_Someparameter_As_SomeValue_Then_Result_Is_Something-Failed.txt
Get-ChildItem *.txt -name
# I would have loved for this to work:
(Get-ChildItem *.txt -name) -join ','

结果不包括文件,因为路径+文件名太长.也没有错误或警告.

The result does not include the file, since the path+filename are too long. There's no error or warning either.

作为一种解决方法,我使用了一个 cmd 脚本文件:

As a work around I'm using a cmd script file with for:

for %%a in (%XMLPath%\*.xml) do ( ... build comma separated list with %%a ... )

如何在 Powershell 中包含(也包括)长名称的完整列表?

How can I the full list including (too?) long names in Powershell?

推荐答案

这似乎是一个非常受欢迎的问题,因为它已在本网站上被问过多次.无论如何,这里有您的替代方案:

This seems to be a really popular question because it has been asked multiple times on this site.Anyway here are your alternatives:

使用 Pinvoke

Boe Prox - Technet

使用 Robocopy

Boe Prox - Technet

在 Powershell V5 和 V4 中使用 AlphaFS

如果您能找到一台装有 PowerShell v5 的计算机(Windows 10 附带 PS v5),您可以安装一个名为 PSAlphaFS .

if you can find a computer with PowerShell v5 (windows 10 comes with PS v5) you can install a module called PSAlphaFS .

Install-Module PSAlphaFS

默认情况下,powershellgallery 中的模块会安装到

by default the modules from powershellgallery get installed to

C:\Program Files\WindowsPowerShell\Modules

注意:PSAlphaFS 模块也可以在带有 PowerShell V4 的目标系统上运行,但不能在 powershell V3 上运行.

Note:The PSAlphaFS module can also be run on a target system with PowerShell V4 but not on powershell V3.

您可以通过以下方式找出当前正在运行的 Powershell 版本.

Here is how you can find out the version of Powershell that is currently running.

$PSVersionTable.PSVersion

一旦模块就位,您就可以然后运行以下类似于 get-childitem 但没有 260 个字符限制的命令.

Once the module is in place you can then run the following command which is similar to get-childitem but without the 260 char limitation.

Get-LongChildItem  -Filter *.txt -Name

这篇关于获取文件夹中的所有文件,包括那些具有长(> 256 个字符)路径 + 名称的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆