我想知道是否仍然使用第一个文件的日期(lastmodified)作为开始日期并从中计算-14天?我的目标是选择该限制内的所有文件并将其列在文本文件中。我无法按日期对文件进行排序,并选择文件夹的第一个文件,因为我必须对同一文件夹中具有特定模式的多个文件执行此操作。
答案 0 :(得分:1)
请注意,FileInfo的LastWriteTime属性为DateTime。有AddDays()方法,所以让我们使用它。像这样,
$f = gci c:\temp\myTestFile.txt # Sample file
$twoWeeksAgo =$f.LastWriteTime.AddDays(-14) # Calculate a date from the past
gci C:\Temp\ | ? { # Get a list of files
$_.LastWriteTime -ge $twoWeeksAgo # that have fresh enough last write time
}