This is literally the first ever batch script I've ever written. I'm trying to iterate through the current folder, find all the .mp3 files and then create a folder for each mp3 file with the same title as the file but without the file extension (then move the file into its respective folder add called ffmpeg to split them into shorter chunks but I haven't gotten to that point yet).
I've found a method here to basically exactly what I need to do. I've also found questions here and here which kinda show how to do the assignment of the of the environment variable to the for loop variable, however its not working for me.
This is my code.
@ECHO OFF
cd C:\test
for %%i in (*.mp3) do (
echo %%i
set episodeName=%%i
set episodeName=!episodeName:~0,-4!
echo !episodeName!
mkdir !episodeName!
)
This is my output.
C:\test>"file splitter.bat"
171 Election.mp3
!episodeName!
172 24 Hours at the Golden Apple.mp3
!episodeName!
A subdirectory or file !episodeName! already exists.
What stoopid obvious mistake am I making?
setlocal enabledelayedexpansioninstruction line which should be placed directly after the@echo offlineechoing%%~ni.%%~niand%%iand they both just echoed the same thing, what's the difference in the two commands?%%ishould show the full name including the.mp3, whereas%%~nishould show the name part only, without the.mp3. The point being that using%%~nishould mean that you don't needepisodenameat all, you don't need to remove the last 4 characters, and if you decide to use the same mechanism to remove some other extension with a different length, there are no changes to make other than specifying the new extension.