none
What am I missing? RRS feed

  • Question

  • Hello all,

    I'm hoping that I have a quick question that someone can answer at first glance. I have a CSV file with one column of File names; I'm trying to recursively search  directory for each one and output only that info (which will eventually be piped to a copy-item cmdlt. The code below runs, but nothing is output (and I know that some of the files exist in this 'folder' directory). 

    When I filter on name; it's searching the full filename - ie 1234.jpg not 1234; correct? Any other pointers on a better way to do this? (Looking for a way to find/copy 9,000 files within a directory structure into a single folder). Thanks in advance for any insight!

    $FileSrc = "sourcepath\folder\"
    $csvfile = "sourcepath\test.csv"
    get-content $csvfile|
    foreach-object ($csvfile.'File') |get-childitem -path "$FileSrc" -filter "name -match $csvfile.'File'" -recurse| write-host

    • Moved by Bill_Stewart Tuesday, December 11, 2018 9:42 PM Abandoned
    Wednesday, August 1, 2018 2:24 AM

All replies

  • If you read the help you will find that the file system provider does not implement "Filter".  It only supports "Include".

    With the file system provider the Filter works exactly like "Include'

    Get-ChildItem -Filter *.txt


    \_(ツ)_/


    • Edited by jrv Wednesday, August 1, 2018 2:39 AM
    Wednesday, August 1, 2018 2:37 AM
  • Hello,

    I suggest you use the 'Import-csv' cmdlet instead of get-content in order to actually get your content per column

    Here is what i would do :

    $FileSrc = "sourcepath\folder\"
    $csvfile = "sourcepath\test.csv"
    
    $Files = (Import-Csv $csvfile).File
    Foreach($file in $files){
        get-childitem -path "$FileSrc" -File -Name "*$file*" -Recurse
    }
    

    Get-childitem will prompt you the results so you don't need the 'Write-host'

    Hope it will help

    Wednesday, August 1, 2018 7:59 AM