Hi,
I try to get all files of a folder which have been modified after a certain date. I know this question has already been asked before, and I found several solutions / proposals, but none worked. And concerning the particular behaviour I encountered, I found nothing, maybe someone can help?
To test, I have a folder with three files, two with lmd in 07/24, one with 09/24. I run the same program, once to find files modified after 01-07-24 (locale is Germany, so dd-mm-yy) and it works, as expected the three files are found. I run it again with the date of 01-08-24 and the output becomes completely weird.
Here the program:
$sourceFolder = "d:\test"
#sourceFolder contains 3 files, 2 with date 07/24, one with date 09/24
Function List-Files{
$fn = Get-ChildItem $sourceFolder -File | ? LastWriteTime -gt $ld
$sourceFiles=$fn.FullName
Write-Host $sourceFiles.Length
Write-Host $fn.Length
if($sourceFiles -eq $null){
Write-Host "null"
exit
}
for($k=0; $k -lt $sourceFiles.Length; $k++){
Write-Host $sourceFiles[$k]
}
Write-Host "************************"
}
$ld = Get-Date("01-07-24")
List-Files
$ld = Get-Date("01-08-24")
List-Files
and here the output
3
3
D:\test\file_0107.txt
D:\test\file_1307.txt
D:\test\file_1509.txt
************************
21
657
D
:
\
t
e
s
t
\
f
i
l
e
_
1
5
0
9
.
t
x
t
************************
Any idea?
Thanks!