year and countryname extract

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
sshree43
Posts: 33
Joined: Wed Jun 27, 2018 11:57 am

Re: year and countryname extract

Post by sshree43 » Mon Jul 09, 2018 1:35 am

I am able to move the date based on year...but for the multiple country of same yearnot moving so wants join country also with it so the formula is country+ year + max(last modified date)..so it should find the character

Code: Select all

Mode       Last Modified date       Length     Filename

-a---         6/25/2018  12:08 AM      31744  abc_Italy_2016_2 - Copy - Copy.xls
-a---         6/25/2018  12:07 AM      31744  abc_Italy_2016_2 - Copy.xls
so it should check the character between 1st space and 2nd '_' like Italy & year then last modified date

User avatar
jvierra
Posts: 13682
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: year and countryname extract

Post by jvierra » Mon Jul 09, 2018 1:44 am

I am sorry but I cannot keep up. You have changed your request repeatedly. This is because you have no experience with PowerShell and cannot explain what it is yu want in any way that I or anyone else can understand. I recommend that you find a consultant who understands your language and can work with you to design a solution to your liking.

Technical forums are not for free consulting. We can answer questions and help but the details needed to obtain information from non-technical workers and turn them into a solution are beyond the scope of these forums.

You have now asked your question in more than 5 different ways in multiple forums. Time to find a consultant you can work with.

Again, I apologize but cannot continue going around in circles.

User avatar
sshree43
Posts: 33
Joined: Wed Jun 27, 2018 11:57 am

Re: year and countryname extract

Post by sshree43 » Mon Jul 09, 2018 2:00 am

ok i am not the right person but can you give the logic in where or like condition for this or you do not know at all

so it should check the character between 1st space and 2nd '_' like Italy & year then last modified date

User avatar
jvierra
Posts: 13682
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: year and countryname extract

Post by jvierra » Mon Jul 09, 2018 2:07 am

I do not know because I cannot understand what you are asking. I have answered the same question in multiple forums and always you ask a new question with different rules.

I cannot help you.

User avatar
sshree43
Posts: 33
Joined: Wed Jun 27, 2018 11:57 am

Re: year and countryname extract

Post by sshree43 » Mon Jul 09, 2018 2:09 am

Get-ChildItem -File -Path $sourcedir|
select *, @{n='Year';e={($_.Basename -split '_')[2]}}
Group-Object Year |
ForEach-Object {
$_.Group | Sort-Object LastWriteTime -Descending |
Select-Object -First 1
}

how can this solve the purpose.. can you please explain

User avatar
jvierra
Posts: 13682
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: year and countryname extract

Post by jvierra » Mon Jul 09, 2018 2:12 am

Please try to understand. I cannot help yu because I cannot understand what you are asking.

You would do better to either get someone who understands English better or post in a forum that is in your own language. Part of the issue may just be that you are not using English correctly.

If this is important then please contact a consultant to help you. After almost a week you should understand that we are not able to decode your questions.

User avatar
sshree43
Posts: 33
Joined: Wed Jun 27, 2018 11:57 am

Re: year and countryname extract

Post by sshree43 » Mon Jul 09, 2018 2:24 am

i think you must understand you own login...or you do not know

User avatar
sshree43
Posts: 33
Joined: Wed Jun 27, 2018 11:57 am

Re: year and countryname extract

Post by sshree43 » Mon Jul 09, 2018 10:16 am

i tried again but not working

$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
}
showing null arrray error

User avatar
jvierra
Posts: 13682
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: year and countryname extract

Post by jvierra » Mon Jul 09, 2018 10:24 am

Remove "Descending. "Skip 1" must be "First 1".

User avatar
sshree43
Posts: 33
Joined: Wed Jun 27, 2018 11:57 am

Re: year and countryname extract

Post by sshree43 » Mon Jul 09, 2018 10:47 am

when i comment #Group-Object $Matches[1] | the query stopped giving error..do i have to define

Locked