开发者

script to pick the most recent file created in a folder in a distributed system?

script to pick the most recent file created in a folder?

The scenario is as beloow:

I have to pick the 2 files which are created recently and开发者_Go百科 i have to copy it to another folder. What script can be used to perform this in a distributed system?


Have you considered to use powershell? It's a great tool for this kind of tasks

gci c:\source | ? {-not $_.psiscontainer} | 
sort-object creationtime -desc | select -first 2 | copy-item -destination c:\destination

This script searches only files within a specified folder, then it sorts files in reverse order by creation time, retrieves only the 2 more recents and finally copy them in you destination folder. Very simple with a short code. Hope that it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜