My snippet generates a csv that lists the path (FullName
) to a long path name comprised of 260 a's, i.e. aaaa*.txt
.
If i have a list of files (.csv) that might each be buried at the end of a long path name, for example: longpath1\file1.txt
, longpath1\file2.txt
, and longpath1\file3.txt
.
How would I amend my code to look for each file I have in the csv list?
Get-LongChildItem -Path $source -Recurse *aaaa*.txt |
Select-Object -Property FullName |
Export-Csv -NoTypeInformation -Delimiter '|' -Path $outputPath
Note that I'm using Get-LongChildItem
from the PSAlphaFS module as posted here and here.
UPDATE:
I've changed my code as per below, where TestFindFile.csv contains a list of the file names I'm searching for:
$source = 'C:\Data\SCRIPTS'
#$outputPath = 'C:\data\scripts\ps1\TestFileLocation6.csv
$destination = 'C:\Data\SCRIPTS'
$searchFiles = Import-CSV 'C:\Data\SCRIPTS\PS1\TestFindFile.csv' -Header ("Name")
$sourceList = Get-LongChildItem -Path $source -Recurse
ForEach($File in $searchFiles)
{
$sourceList | Where-Object { $_.Name -match $File.filename } | Copy-Item -Destination $destination
# $sourceList | Where-Object { $_.Name -match $File.filename } | Copy-Item -Destination $destination | export-csv -notypeinformation -delimiter '|' -path $outputPath
}
But I get the error:
Unexpected token 'C:\Data\SCRIPTS'
$searchFiles = Import-CSV 'C:\Data\SCRIPTS\PS1\TestFindFile.csv' -Header ("Name")
$sourceList = Get-LongChildItem -Path $source -Recurse
ForEach($File in $searchFiles)
{
$sourceList | Where-Object { $_.Name -match $File.filename } | Copy-Item -Destination $destination
}
'
in expression or statement.
+ CategoryInfo : ParseError: (:) [], ParseException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString