Cheri
Cheri

Reputation: 31

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

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 file to remain in the original location.

FYI, it needs to be a batch file.

Thanks in advance for your help...

Upvotes: 2

Views: 11813

Answers (2)

micklepickle
micklepickle

Reputation: 11

@echo off
set/a %%/folder
/a copy <folder2>

Upvotes: 1

Aacini
Aacini

Reputation: 67216

@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

Upvotes: 6

Related Questions