I'm trying to delete all images within a folder taken between 8pm and 7am Using Powershell but I'm having some trouble. Unfortunately the information on the images do not have the correct date modified/ date created time but the correct time is stored in the image metadata as Date Taken.
I've tried this
get-ChildItem *jpg | Where-Object{$_.LastWriteTime.TimeOfDay.Hours -gt 20 -or $_.LastWriteTime.TimeOfDay.Hours -lt 07} |Remove-Item
But this deletes everything because the write time is 11pm for all the images. (the image taken date is different for the images)
I have about 3,000 images to sort through. I'm very new to powershell, but it seems like it should work. I can also use Python if people think thats easier...
You need to read the EXIF data (metadata) from inside each image file. Get-ChildItem is only going to return the properties of the file itself, not any metadata inside the file.
Checkout this Microsoft article that describes the process using a COM object to expose the EXIF fields of an image (including Date Taken
). This solution requires a PowerShell function on the technet gallery to actually fetch the EXIF data.
I ended up finding another code that assigns the Date Taken to the Date Created property. So then I could run the original code I posted. I dont really need anything efficient so this got the job done.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.