Asked by:
how to pickup files which today date

Question
-
Hi Jrv
how to pickup files which today date -1 rather "$folder/*.txt"
date Format is YYYYMMDD.(ex data-20170509.txt)
thanks
- Split by jrv Wednesday, January 3, 2018 2:45 PM New question
Wednesday, January 3, 2018 3:51 AM
All replies
-
Hi Jrv, I modify the script as follows to pickup yesterday files. But files are not pickup. but no errors on the script.
$ydate = (get-date (get-date).AddDays(-1) -format yyyyMMdd)
$folder = 'C:\DataLoading\data'
$ydate = (get-date (get-date).AddDays(-1) -format yyyyMdd)
Get-ChildItem "$folder/*$ydate.txt" |
ForEach-Object{
$target = ($_.Name -split '-')[0]
If(!(test-path $folder\$target))
{
New-Item -ItemType Directory -Force -Path $folder\$target
}
}
Get-ChildItem "$folder/'*$ydate.txt" |
ForEach-Object{
$target = ($_.Name -split '-')[0]
$_ | Move-Item -Destination $folder\$target
}
Thanks
Wednesday, January 3, 2018 8:38 AM -
Hi,
Based on my research, I recommend using (Get-Date).AddDays(-1).ToString('yyyyMMdd') to get yesterday's date. The following script for your reference, hope it is helpful to you:
$ydate = (Get-Date).AddDays(-1).ToString('yyyyMMdd') $folder = 'C:\DataLoading\data' Get-ChildItem -Path $folder | Where-Object {$_.Name -like "*$ydate.txt"} | ForEach-Object { $destination = New-Item -Path $folder -Name ($_ -split '-')[0] -ItemType Directory -Force $_ | Move-Item -Destination $destination }
If you need further help, please feel free to let us know.
Best Regards,
AlbertPlease remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com- Proposed as answer by Albert LingMicrosoft contingent staff Tuesday, January 9, 2018 2:37 AM
Wednesday, January 3, 2018 11:05 AM -
Hi,
Just checking in to see if the information provided was helpful. Does the script work?
Please let us know if you would like further assistance.
Best Regards,
AlbertPlease remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.comFriday, January 5, 2018 3:12 AM -
Hi,
I am checking how the issue is going, if you still have any questions, please feel free to contact us.
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Appreciate for your feedback.
Best Regards,
AlbertPlease remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.comTuesday, January 9, 2018 2:37 AM