It is necessary to select the newest files from one folder (with a bunch of subfolders) and copy them to another folder. I figured out the copy, but I don’t understand how to select the exact files that I need.

Search prompted: Get-ChildItem | Where-Object{$_.CreationTime.Day -like "23"} Get-ChildItem | Where-Object{$_.CreationTime.Day -like "23"} . But this is exactly for a particular day sampling.

Do not tell me where to look, not to take all the dates of files, sort, and then choose? If in no other way how to do it faster? There are just a lot of files, so this script will be processed for very long.

To use anything other than Powershell and cmd is impossible.

  • not to take all the file dates, sort, and then choose? incomprehensible question. How will you determine that the file is new? Complete your question by clicking on the edit button - Senior Pomidor
  • Defrag look on Monday, thanks. Senior Pomidor is the whole problem, the files (30kb -5mb each) are more than 16TB, because the standard methods do not work. Defrag suggested a good idea with the "file was created \ edited x time ago" unfortunately I can try it only on Monday. - Yuki A
  • Although I thought that he would have to scan all the files vseravno .. But let's see how it works. - Yuki A
  • I edited it, the question of how to do it faster, if it’s different in any other way is relevant, on Monday I’ll try what they’ve suggested, I will unsubscribe. - Yuki A

1 answer 1

So satisfied?

 setlocal EnableDelayedExpansion set idx=0 for /f %%i in ('dir /A:-D /B /O:-D') do ( copy %%i 1\ set /a idx= !idx! + 1 if !idx!==5 exit ) 

We execute the dir command with sorting files in descending order and after the first 5 files we exit

  • Will it work for subfolders? - Yuki A
  • For subfolders add the key /s - Anton Shchyrov
  • I will try on Monday, thanks. - Yuki A