none
Parse through a directory and identify and copy.move files to an archive folder

    Question

  • I have a dilemma and dont really have a clue how to solve this.

    I have been given the task to remove a list of files

    They are in a one parent directory C:\data1\data2

    however the files are individually located in numerous nested directories

    C:\data1\data2\folder1\folder2\xxx.exe

    C:\data1\data2\folder1\folder2\folder3\file.zip

    C:\C:\data1\data2\folder1\folder2\folder3\xxx.txt

    I receive the files names in a spreadsheet and copy the path to a holding file named removal.txt

    I tired using the following script to identify the files and populate them (this way i can produce to data owner for verification)

    Get-childItem -Path C:\data1\data2\* -Recurse -include(Get-Content "C:\data1\data2\removal.txt") -verbose |Out-File -filepath "C:\data1\data2\\utput.txt"

    when i run this query i dont get any output 

    however if i only insert the file names in the removal.txt i.e. 

    xxx.exe

    file.zip

    xxx.txt

    i get the output with the data required

    what do i need in order for this to work?


    Priyantha Perera

    Wednesday, January 9, 2019 11:05 PM

All replies

  • Simplify.

    $files = Get-Content C:\data1\data2\removal.txt
    Get-childItem -Path C:\data1\data2\* -Recurse -include $files


    \_(ツ)_/

    Wednesday, January 9, 2019 11:28 PM