2

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...

Cheri
  • 31
  • 1
  • 1
  • 4
  • Batch file for what kind of operating system? Windows, linuxes (+unix) and OS X have different languages to implements such functionality. – рüффп Sep 22 '13 at 16:00
  • Windows... sorry that I didn't specify this from the beginning. I will edit the question to reflect the operating system. – Cheri Sep 22 '13 at 18:18
  • @Cheri: That is not necessary; the `batch-file` tag clearly indicate: "Script files containing a series of commands that are executed by the Windows command-line interpreter". – Aacini Sep 22 '13 at 18:25
  • Okay, I will accept it... just testing it out first. – Cheri Sep 22 '13 at 21:57

2 Answers2

6
@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
Aacini
  • 61,954
  • 12
  • 66
  • 99
1
@echo off
set/a %%/folder
/a copy <folder2>
Zoe stands with Ukraine
  • 25,310
  • 18
  • 114
  • 149