1

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
Community
  • 1
  • 1
val
  • 1,629
  • 1
  • 30
  • 56
  • The question isn't clear to me. Why would you need to look for the files if you already have the paths in your CSV? Do you want to validate the paths? Are the paths incomplete and you need to search for the files? – Ansgar Wiechers Jun 30 '16 at 08:33
  • @AnsgarWiechers: apologies for not being clear. I don't know where the files are. I only have the name of the file in the CSV, not the full path. I have added an UPDATE to my question. – val Jun 30 '16 at 08:35

0 Answers0