Page 3 of 3

Re: year and countryname extract

Posted: Mon Jul 09, 2018 3:00 pm
by jvierra

Code: Select all

Get-ChildItem $source -FIle |
    Select-Object *, @{n='year';e={($_.Basename -split '_')[2]}},@{n='Country';e={($_.Basename -split '_')[1]}}
    Group-Object Year,Country |
    Select-Object -expand Group |
    Sort-Object LastWriteTime |
    Select-Object -First 1 |
    Move-Item -Destination $destination

Re: year and countryname extract

Posted: Mon Jul 09, 2018 10:32 pm
by sshree43
when i run this file...only half of the files are moving

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

Get-ChildItem -File -Path $sourcedir |
Where-Object BaseName -match ' ([a-z]+_20\d{2})_\d' |
Group-Object {$Matches[1]} |
ForEach-Object {
$_.Group | Sort-Object LastWriteTime -Descending |
Select-Object -Skip 1 |
Move-Item -Destination $destdir -Force
}

i think it is unable to find year and country and only year can get results

Re: year and countryname extract

Posted: Wed Jul 11, 2018 2:19 am
by sshree43
any suggestions on this i am little bit away from the target as able to move some of the files. here is the new file format first row should be archived

abc N Refund Maker_Japan_2017_302413 modified date :26/06 10:20
abc N Refund Maker_Japan_2017_Extra modified date:26/06 10:30