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

后端 未结 4 1222
小蘑菇
小蘑菇 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:50

    The following Batch code will do it. Note that you will need to launch cmd using the following command line:

    cmd /v:on
    

    to enable delayed environment variable expansion. Note also that it will pick a random number of files from 0 to 32767 - you will probably want to modify this part to fit your requirements!

    @ECHO OFF
    SET SrcCount=0
    SET SrcMax=%RANDOM%
    FOR %F IN (C:\temp\source\*.*) DO IF !SrcCount! LSS %SrcMax% (
          SET /A SrcCount += 1
          ECHO !SrcCount! COPY %F C:\temp\output
          COPY %F C:\temp\output
          )
    

提交回复
热议问题