windows batch file script to pick random files from a folder and move them to another folder

后端 未结 4 1232
小蘑菇
小蘑菇 2020-12-10 07:21

I need a batch script to randomly select X number of files in a folder and move them to another folder. How do I write a windows batch script that can do this?

4条回答
  •  长情又很酷
    2020-12-10 07:37

    (I'm assuming that your X is known beforehand – represented by the variable $x in the following code).

    Since you weren't adverse to a PowerShell solution:

    Get-ChildItem SomeFolder | Get-Random -Count $x | Move-Item -Destination SomeOtherFolder
    

    or shorter:

    gci somefolder | random -c $x | mi -dest someotherfolder
    

提交回复
热议问题