Powershell - How to check if file with desired creation time exists?

随声附和 提交于 2019-12-05 02:45:57

问题


I'm using this script

$date = Get-Date
Get-Childitem -name | where {$_.CreationTime -eq "$date"}

but it doesn't work. All I need is to do a boolean check if there is a file created in specific date. Thank you.


回答1:


Get-Date gets the current date and time. If you compare a file's creation date with the current date and time you won't find any files (except you just have created one while retrieving the current date ;) ).

$today = (get-date).Date
Get-ChildItem | where { $_.CreationTime.Date -eq $today }



回答2:


Get-ChildItem | where-object { $_.CreationTime.Date -match "2014" }

where 2014 is the year of creation.



来源:https://stackoverflow.com/questions/10433339/powershell-how-to-check-if-file-with-desired-creation-time-exists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!