Need to create a batch file to select one random file from a folder and copy to another folder

前端 未结 2 960
长发绾君心
长发绾君心 2020-12-18 15:15

I need to create a batch file for Windows OS that will select a random file from a particular folder, then copy that file to a different folder. I still need a copy of that

相关标签:
2条回答
  • 2020-12-18 15:37
    @echo off
    set/a %%/folder
    /a copy <folder2>
    
    0 讨论(0)
  • 2020-12-18 15:56
    @echo off
    setlocal EnableDelayedExpansion
    cd \particular\folder
    set n=0
    for %%f in (*.*) do (
       set /A n+=1
       set "file[!n!]=%%f"
    )
    set /A "rand=(n*%random%)/32768+1"
    copy "!file[%rand%]!" \different\folder
    
    0 讨论(0)
提交回复
热议问题