简体   繁体   中英

Copy files with certain extension created within last half an hour with powershell

I'm trying to copy files (.zip) that has been created in the last half an hour and using the below script for that but for some reason all the zip files in the source directory get copied over. Can you please help me in correcting it?

copy-item C:\ABC\\*.zip -filter (Get-ChildItem | Where{$_.CreationTime -ge (Get-Date).AddMinutes(-30)}) -destination C:\

Try the following:

Get-ChildItem C:\ABC\*.zip | Where { $_.CreationTime -ge (Get-Date).AddMinutes(-30) } | % { Copy-Item $_.FullName -destination C:\ }

I am not sure why filter is not working, but this gets a list of all the zips, filters that down to the ones with the correct times, and then issues the copy statement.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM