Computer Hope
Microsoft => Microsoft DOS => Topic started by: Geek-9pm on August 25, 2018, 03:30:13 PM
-
I have a lot pf MP3 files I want to put on a SB. About 50 files
The cheap MP3 player I have can play the songs. Put I want the order to be broken.
This little player has no way to scramble the order.
So, is there a way I can use a batch file to put a prefix on each file name ?
The files are now in a directory on my PC.
Of course Windows puts them in alpha order.
So when I copy them to the SD card they end up in that order.
But I do not want them in order.
Do you understand what I want?
-
Of course Windows puts them in alpha order.
Windows does not 'put' files in any particular order. It must be your player. So a random alpha prefix might work? Like this?
Apple.mp3 -> pqz_Apple.mp3
Bear.mp3 -> svt_Bear.mp3
Cauliflower.mp3 -> lxn_Cauliflower.mp3
Is that something like what you want?
-
Copy blue text below into Notepad and save as a .bat into folder where you want shuffled names to go. The folder for shuffled files MUST EXIST. You can hopefully see where to make changes to customize. Existing files not changed; new copies created in another folder.
@echo off
setlocal enabledelayedexpansion
REM where to put shuffled files
set shuffledfolder=shuffled
REM length of random letter string
set stringlen=3
REM ASCII values reminder
rem A = 65
rem X = 90
rem a = 97
rem z = 122
REM choose case of prefix letters
REM set to either UPPER or lower
REM case of variable name doesn't matter!
set case=UPPER
REM assign max & min values for random number
REM UPPER CASE
IF /i "%case%"=="UPPER" (
set minval=65
set maxval=90
)
REM LOWER CASE
IF /i "%case%"=="lower" (
set minval=97
set maxval=122
)
echo START PROCESSING FILES
for %%A in (*.mp3) do (
call :makestring
echo %%A ---^> %shuffledfolder%\!rstring!_%%A
copy "%%A" "%shuffledfolder%\!rstring!_%%A"
)
echo FINISHED PROCESSING FILES
pause
exit /b
REM *** SUBROUTINE START
:makestring
REM create empty string
set "rstring="
REM set letter count to zero
set chars=0
REM loop back to here until desired
REM length is generated
:genloop
REM choose a random number between minval and maxval
set /a "ascii=%RANDOM% * (%maxval% - %minval% + 1) / 32768 + %minval%"
REM set errorlevel to that number
cmd /c exit /b %ascii%
REM get letter corresponding to that exit code
set letter=%=ExitCodeAscii%
REM add that letter to end of string
set rstring=%rstring%%letter%
REM increase letter count by ONE
set /a chars+=1
REM if letter count less than desired length
REM then loop again
if %chars% LSS %stringlen% goto genloop
goto :eof
REM *** SUBROUTINE END
-
(1) Input files
Drive My Car.mp3
Girl.mp3
If I Needed Someone.mp3
I'm Looking Through You.mp3
In My Life.mp3
Michelle.mp3
Norwegian Wood.mp3
Nowhere Man.mp3
Run for Your Life.mp3
The Word.mp3
Think for Yourself.mp3
Wait.mp3
What Goes On.mp3
You Won't See Me.mp3
(2) Output of script
START PROCESSING FILES
Drive My Car.mp3 ---> shuffled\JDZ_Drive My Car.mp3
1 file(s) copied.
Girl.mp3 ---> shuffled\OTC_Girl.mp3
1 file(s) copied.
I'm Looking Through You.mp3 ---> shuffled\ZBJ_I'm Looking Through You.mp3
1 file(s) copied.
If I Needed Someone.mp3 ---> shuffled\SRG_If I Needed Someone.mp3
1 file(s) copied.
In My Life.mp3 ---> shuffled\WFP_In My Life.mp3
1 file(s) copied.
Michelle.mp3 ---> shuffled\WSH_Michelle.mp3
1 file(s) copied.
Norwegian Wood.mp3 ---> shuffled\DEA_Norwegian Wood.mp3
1 file(s) copied.
Nowhere Man.mp3 ---> shuffled\WYY_Nowhere Man.mp3
1 file(s) copied.
Run for Your Life.mp3 ---> shuffled\YAU_Run for Your Life.mp3
1 file(s) copied.
The Word.mp3 ---> shuffled\BQL_The Word.mp3
1 file(s) copied.
Think for Yourself.mp3 ---> shuffled\QDL_Think for Yourself.mp3
1 file(s) copied.
Wait.mp3 ---> shuffled\RZD_Wait.mp3
1 file(s) copied.
What Goes On.mp3 ---> shuffled\PHE_What Goes On.mp3
1 file(s) copied.
You Won't See Me.mp3 ---> shuffled\TZP_You Won't See Me.mp3
1 file(s) copied.
FINISHED PROCESSING FILES
Press any key to continue . . .
(3) Result in shuffled folder:
BQL_The Word.mp3
DEA_Norwegian Wood.mp3
JDZ_Drive My Car.mp3
OTC_Girl.mp3
PHE_What Goes On.mp3
QDL_Think for Yourself.mp3
RZD_Wait.mp3
SRG_If I Needed Someone.mp3
TZP_You Won't See Me.mp3
WFP_In My Life.mp3
WSH_Michelle.mp3
WYY_Nowhere Man.mp3
YAU_Run for Your Life.mp3
ZBJ_I'm Looking Through You.mp3
-
Same script minus comments and blank lines
@echo off
setlocal enabledelayedexpansion
set shuffledfolder=shuffled
set stringlen=3
set case=UPPER
IF /i "%case%"=="UPPER" (
set minval=65
set maxval=90
)
IF /i "%case%"=="lower" (
set minval=97
set maxval=122
)
echo START PROCESSING FILES
for %%A in (*.mp3) do (
call :makestring
echo %%A ---^> %shuffledfolder%\!rstring!_%%A
copy "%%A" "%shuffledfolder%\!rstring!_%%A"
)
echo FINISHED PROCESSING FILES
pause
exit /b
:makestring
set "rstring="
set chars=0
:genloop
set /a "ascii=%RANDOM% * (%maxval% - %minval% + 1) / 32768 + %minval%"
cmd /c exit /b %ascii%
set letter=%=ExitCodeAscii%
set rstring=%rstring%%letter%
set /a chars+=1
if %chars% LSS %stringlen% goto genloop
goto :eof
-
Thank you.
That will be fun to test. ;)
-
Later today...
Just tried it on a group of small MP3 files.
I tested just then tracks to see what would happen. After I got the folder relations right, it worked perfectly. That BAT has to be inside the MP3 folder and the snuffled folder has to be there also.
It did a nice job of putting tracks in a scramble order.
The new order is:
6 5 10 8 7 9 1 2 4 3
Salmon trout, you are amazing! :)
-
Of course you can make the folder, where the shuffled files go, anywhere you like. See the line in red below.
@echo off
setlocal enabledelayedexpansion
set shuffledfolder=c:\some\folder\whatever
set stringlen=3
set case=UPPER
IF /i "%case%"=="UPPER" (
set minval=65
set maxval=90
)
IF /i "%case%"=="lower" (
set minval=97
set maxval=122
)
echo START PROCESSING FILES
for %%A in (*.mp3) do (
call :makestring
echo %%A ---^> %shuffledfolder%\!rstring!_%%A
copy "%%A" "%shuffledfolder%\!rstring!_%%A"
)
echo FINISHED PROCESSING FILES
pause
exit /b
:makestring
set "rstring="
set chars=0
:genloop
set /a "ascii=%RANDOM% * (%maxval% - %minval% + 1) / 32768 + %minval%"
cmd /c exit /b %ascii%
set letter=%=ExitCodeAscii%
set rstring=%rstring%%letter%
set /a chars+=1
if %chars% LSS %stringlen% goto genloop
goto :eof
-
Right.
It was easy to just make a new folder. After the job was done, I copied the shuffled stuff to the memory card of the MP3 player.
Sot I will note that for future reference, I could have just mdse the MP3 player the target using a USB cable. :)