country,year,last modified date as parameter to exclude the files

This topic contains 2 replies, has 2 voices, and was last updated by  L-Bo 3 weeks, 1 day ago.

  • Author
    Posts
  • #103312

    s
    Participant

    I am moving the files which are less than last modified date file to the Archive folder
    but I wanted to put parameter and not to move the files to archive
    which country wise max year and max modified date for an example
    file1_itlay_2017.xlsx last modified date is 26/6/2018 10:24 AM

    file1_itlay_2018.xlsx last modified date is 26/6/2018 10:24 AM
    in this case it should fetch country,year and last modified date for that partucular year
    so in output both file will be excluded
    Requirement:exlcude file via year,country and last modfied date
    i can able to achieve last modified date from below mentioned syntax

    $sourcedir = 'C:\Users\garang\Documents\input_files\Advisory_rate'
    $destdir = 'C:\Users\garang\Documents\input_files\Advisory_rate\Archive'

    Get-ChildItem -File -Path $sourcedir |
    Sort-Object -Property LastWriteTime -Descending |
    Select-Object -Skip 1 |
    Move-Item -Destination $destdir -force

  • #103318

    s
    Participant

    suggestion please

  • #103417

    L-Bo
    Participant

    Use Where-Object to further refine the results. See the example below

    $country = 'italy'
    $year = 2018
    
    Get-ChildItem -File -Path $sourcedir | Where-Object {$_.name -match $country -and $_.Name -match $year} |
     Sort-Object -Property LastWriteTime -Descending |
     Select-Object -Skip 1 | Move-Item -Destination $destdir -force
    

You must be logged in to reply to this topic.