问题描述
此问题是 PowerShell的扩展-搜索现有文件会生成空输出.
我无法使用AlphaFS捕获长文件路径名.我看过相关的AlphaFS问题,但看不到它们如何解决我的问题:以下代码旨在将$ source目录中的文件捕获到.csv中,包括路径长度超过260个字符的文件.但是,我在TestFileLocations.csv中获得的输出由1行组成,内容为:
I'm having trouble capturing long file path names with AlphaFS. I've looked at related AlphaFS questions but I can't see how they address my issue: The code below is intended to capture files in a $source directory into a .csv, including those with paths that are longer than 260 characters. However, the output I get in TestFileLocations.csv consists of 1 line that reads
IsReadOnly|"IsFixedSize"|"IsSynchronized"|"Keys"|"Values"|"SyncRoot"|"Count"
其后为125060行,其内容为
followed by 125060 lines that read
False|"False"|"False"|"System.Collections.Hashtable+KeyCollection"|"System.Collections.Hashtable+ValueCollection"|"System.Object"|"1"
PS代码
[System.Reflection.Assembly]::LoadFrom('C:\AlphaFS\AlphaFS\lib\net35\AlphaFS.dll')
$searchFiles = Import-CSV 'C:\Data\SCRIPTS\PS1\TestFindFile.csv' -Header ("Name")
$source = 'C:\Data\Scripts'
$outputPath = 'c:\data\scripts\ps1\TestFileLocation.csv'
$searchFiles | ForEach-Object {
$files = [Alphaleonis.Win32.Filesystem.Directory]::EnumerateFileSystemEntries($source,'*',[System.IO.SearchOption]::AllDirectories)
$files | ForEach-Object { [PSCustomObject] @{FileName = $_} }
} | export-csv -notypeinformation -delimiter '|' -path $outputPath
我的TestFindFile.csv仅包含4行代码,这些行与应通过代码找到的3个现有文件有关.最后一个文件有262个字符:
My TestFindFile.csv contains only 4 lines pertaining to 3 existing files that should be found by the code. The last file has 262 characters:
Name
123.pdf
321.pdf
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt
我在Windows 7上.任何指针将不胜感激.
I'm on Windows 7. Any pointers would be appreciated.
推荐答案
我将Alphafs包装到一个PS模块中,您可以在此处的PowerShell库中找到它.
I wrapped Alphafs into a PS module which you can find on the PowerShell Gallery here.
因为它是一个模块,所以我无法发布整个代码,但是可以包含一个链接,您可以从中下载它.
Since it is a module I cannot post the whole code but can include a link from where you can download it.
有了模块后,您可以执行以下操作:
Once you have the module you can do something like this :
Get-LongChildItem -path yourpath | export-csv output.csv -notype
这篇关于PowerShell-如何使用此代码+ AlphaFS捕获文件路径名,包括长文件路径名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!