year and countryname extract

Ask your 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.
This topic is 5 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
sshree43
Posts: 33
Last visit: Wed Jul 18, 2018 8:53 am

Re: year and countryname extract

Post by sshree43 »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: year and countryname extract

Post by jvierra »

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
Last visit: Wed Jul 18, 2018 8:53 am

Re: year and countryname extract

Post by sshree43 »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: year and countryname extract

Post by jvierra »

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
Last visit: Wed Jul 18, 2018 8:53 am

Re: year and countryname extract

Post by sshree43 »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: year and countryname extract

Post by jvierra »

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
Last visit: Wed Jul 18, 2018 8:53 am

Re: year and countryname extract

Post by sshree43 »

i think you must understand you own login...or you do not know
User avatar
sshree43
Posts: 33
Last visit: Wed Jul 18, 2018 8:53 am

Re: year and countryname extract

Post by sshree43 »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: year and countryname extract

Post by jvierra »

Remove "Descending. "Skip 1" must be "First 1".
User avatar
sshree43
Posts: 33
Last visit: Wed Jul 18, 2018 8:53 am

Re: year and countryname extract

Post by sshree43 »

when i comment #Group-Object $Matches[1] | the query stopped giving error..do i have to define
This topic is 5 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked