Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 546
culter Avatar asked Jan 16 '23 19:01

culter


2 Answers

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 }
like image 148
Stefan Avatar answered May 10 '23 07:05

Stefan


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

where 2014 is the year of creation.

like image 28
dsmanneke Avatar answered May 10 '23 08:05

dsmanneke