batch file to copy random file every 60 sec.

October 3, 2011 at 07:33:43
Specs: Windows 7 64 bit, Intel I3 / 4G
I dj at a club, and every 60 sec. I play a different jingle (mp3 file). I have 50 mp3 file in a folder. I would like to create a batch file to randomly copy, rename and over write one of the 50 file to another folder every 60 sec.

See More: batch file to copy random file every 60 sec.

Report •

#1
October 3, 2011 at 19:25:44
This sounds like a cool project. There is a random environment variable in windows %random%, it generates a number between 0 and 32767, and I'm trying to think of a way to use that to call a random file. I guess you could rename the files 0.mp3 to 49.mp3, and then do an if not exist %random%.mp3. If it doesn't exist have it go back to the top of the if exist, if it does exist, have it copy the .mp3 and then timeout 60.

@echo off

:start
set file=%random%
if not exist %file%.mp3 goto start
copy /y "c:\original_directory\%file%.mp3 c:\new_directory\%file%.mp3
timeout 60
goto start

I haven't tested this, and I have a feeling it will be kinda slow, so you probably won't get a result every 60 seconds reliably. There are too many numbers in that variable. There's probably a better way. I'll think about it some more and post what I come up with.


Report •

#2
October 4, 2011 at 06:46:28
Jowah, thank you very much, Added "Quotes" to "c:\original_directory\%file%.mp3", Works like a charm, Is it possible to do this without renaming the files, I will search the forum for a random file copy.Thanks again

Report •

#3
October 4, 2011 at 11:39:52
I'm sure there is a way dfyffe but I'm not sure what it is. I'll keep thinking about it and let you know.

Report •

Related Solutions

#4
October 4, 2011 at 18:16:01
Thanks to Mechanix2Go This work without renaming files.

@echo off & setLocal enableDELAYedeXpansioN
:start
set T=
for /f "tokens=* delims= " %%a in ('dir/b') do (
set /a T+=1
)
set /a S = !random! %% T + 1

set N=
for /f "tokens=* delims= " %%a in ('dir/b') do (
set /a N+=1
if !S! equ !N! (copy /y "%%a" "c:\your folder\filename.ext")
)
timeout 60
goto start


Report •

#5
October 11, 2011 at 11:32:29
How could I get this to copy random file from multiple folder to same folder with a different file name ?.

Report •

Ask Question