Solved Batch File that grabs file names from folder to insert into batch file

G33kman

New member
Local time
9:31 AM
Messages
6
Location
Mankato,MN
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused:

First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg.

Here's the code that I'm using:

ffmpeg -i folder\video.mp4 -f mp3 -ab 160000 -vn "\different folder\music.mp3"

what I would like to do is add to this so that I don't have to write out this code for every file I have... :/

I have the mp4 files in one folder and than the mp3 files are saving to another folder.

So here's an example of what the code will do if it isn't clear yet.

Folder 1:

video1.mp4
video2.mp4
video3.mp4

what it should do is grab video1.mp4 and convert it.

ffmpeg -i folder\video1.mp4 -f mp3 -ab 160000 -vn "\different folder\music1.mp3"

and than move onto the next one

ffmpeg -i folder\video2.mp4 -f mp3 -ab 160000 -vn "\different folder\music2.mp3"

and than the next one

ffmpeg -i folder\video3.mp4 -f mp3 -ab 160000 -vn "\different folder\music3.mp3"

It's going to have to grab the name from the mp4 file and insert it for the mp3 file.

I can get around pretty good in cmd if it's basic commands but when it comes to something like this I'm a little confused...

Thanks for the help in advance!
I'll see what i can do about searching some more on what I would have to do and if I find the solution I'll post it here if it isn't already answered.
 

My Computer My Computer

Computer Manufacturer/Model Number
Toshiba Satellite (L505-S5988)
OS
Windows 7 (6.1.7600.16385)
CPU
Intel Core 2 Duo T6500 @2.10GHz Socket P (478) 2MB 800MHz
Motherboard
OEM - Chipset: Intel GM45/GM47 Southbridge: 82801IM (ICH9-M)
Memory
(2) Samsung M471B5673EH1-CF8 PC3-8500F (533MHz) Total 4096MB
Graphics Card(s)
Intel Mobile GMA4500MHD
Sound Card
Realtek HD Audio
Monitor(s) Displays
16" TruBrite TFT LCD 1366x768 720p
Hard Drives
Toshiba MK3263GSX 320GB 5400rpm SATA
PSU
65w (19V x 3.42A) AC Adapter
Case
NA
Cooling
Standard
Keyboard
Standard
Mouse
Synaptics TouchPad
Internet Speed
Charter Communications Cable Internet - 20m Down 3m Up
A DOS "for /f" loop should do the trick, although changing the filename extension for the output to do everything in one line escapes me at the moment.

Perhaps you could do a dir .\folder\*.mp4/s/b > mp4s.txt, then make a copy of that and edit each line to rename the file to the destination name, and save it as mp3s.txt. Then you just feed both the source (mp4s.txt) and destination (mp3s.txt) filesnames into the for /f loop which handles the ffmpeg conversion.

Quite a crude solution and you'd have to handpatch the destination filenames, but i can't think of how to get a source mp4 filename and then just change the extension.
 

My Computer My Computer

Computer Manufacturer/Model Number
Self-built rig
OS
Win7 Pro x64
CPU
Koa i5-2550K
Memory
8 GB
Graphics Card(s)
Sapphire ATI 6870 1GB GDDR5
Sound Card
RealTek HD Audio / ATI HDMI Audio
Monitor(s) Displays
Samsung HDTV Monitor T23A350
Screen Resolution
1920 x 1080
Hard Drives
- SSD (C:)
- HDD (D:)
- BD-ROM (E:)
Keyboard
Logitech G110
Internet Speed
Unifi home (5mbps)
Well I have gotten some of it figured out...
What my script does so far:

1) It scans the folder containing the mp4 files and saves the list to a text file with the full path of each mp4 file.

Code:
       dir /s /b "C:\Users\Username\Desktop\Music Stuff\Videos\*.*" > "videolist.txt"

What it shows inside the "videolist" text file:
     C:\Users\username\Desktop\Music Stuff\Videos\Video1.mp4
     C:\Users\username\Desktop\Music Stuff\Videos\Video2.mp4
     C:\Users\username\Desktop\Music Stuff\Videos\Video3.mp4

2) It scans the folder containing the mp4 files again and this time saves the list to a separate text file with just the file name including the extension which isn't a big deal.

   [CODE]
      dir /b "C:\Users\Username\Desktop\Music Stuff\Videos\*.*" > "musiclist.txt"

What it shows inside the "musiclist" text file:
   Video1.mp4
   Video2.mp4
   Video3.mp4

So far this part works I open the text files and each mp4 file is listed on it's own line and looks like it should work, but the issue I'm having is when I use a for /f statement it doesn't seem to want to take one file from the list do the conversion and than move on to the next file on the list... :/

Here's the entire code that I have so far...

   [CODE]

@echo off
dir /s /b "C:\Users\username\Desktop\Music Stuff\Videos\*.*" > "videolist.txt"
dir /b "C:\Users\username\Desktop\Music Stuff\Videos\*.*" > "musiclist.txt"

for /F "tokens=*" %%A in (videolist.tmp) do set video= %%A
for /F "tokens=*" %%A in (musiclist.tmp) do set music= %%A

ffmpeg -i "%video%" -f mp3 -ab 160000 -vn "%music%".mp3

PAUSE

del videolist.txt musiclist.txt


It's not the prettiest code ever but I would think it should work but not so much yet...
Any ideas?
I just need it to take the first line from the videolist.txt file and insert it into the %video% spot and take the first line from the musiclist.txt file and insert it into the %music% spot and than run the conversion and than move on down the list sequentially. Seems easy right?!?! LOL
 

My Computer My Computer

Computer Manufacturer/Model Number
Toshiba Satellite (L505-S5988)
OS
Windows 7 (6.1.7600.16385)
CPU
Intel Core 2 Duo T6500 @2.10GHz Socket P (478) 2MB 800MHz
Motherboard
OEM - Chipset: Intel GM45/GM47 Southbridge: 82801IM (ICH9-M)
Memory
(2) Samsung M471B5673EH1-CF8 PC3-8500F (533MHz) Total 4096MB
Graphics Card(s)
Intel Mobile GMA4500MHD
Sound Card
Realtek HD Audio
Monitor(s) Displays
16" TruBrite TFT LCD 1366x768 720p
Hard Drives
Toshiba MK3263GSX 320GB 5400rpm SATA
PSU
65w (19V x 3.42A) AC Adapter
Case
NA
Cooling
Standard
Keyboard
Standard
Mouse
Synaptics TouchPad
Internet Speed
Charter Communications Cable Internet - 20m Down 3m Up
Well it is figured out!
I was making it WAY more complicated than it needed to be...

Here's the code that worked!

Code:
set dir=C:\Users\Username\Desktop\Music Stuff

for /f "delims=" %%A in ('dir /b "%dir%\Videos\*.*"') do ("%dir%\ffmpeg\bin\ffmpeg" -i "%dir%\Videos\%%~A" -f mp3 -ab 160000 -vn "%dir%\Finished Music\%%~nA.mp3"
)


Thanks for the help though!
 

My Computer My Computer

Computer Manufacturer/Model Number
Toshiba Satellite (L505-S5988)
OS
Windows 7 (6.1.7600.16385)
CPU
Intel Core 2 Duo T6500 @2.10GHz Socket P (478) 2MB 800MHz
Motherboard
OEM - Chipset: Intel GM45/GM47 Southbridge: 82801IM (ICH9-M)
Memory
(2) Samsung M471B5673EH1-CF8 PC3-8500F (533MHz) Total 4096MB
Graphics Card(s)
Intel Mobile GMA4500MHD
Sound Card
Realtek HD Audio
Monitor(s) Displays
16" TruBrite TFT LCD 1366x768 720p
Hard Drives
Toshiba MK3263GSX 320GB 5400rpm SATA
PSU
65w (19V x 3.42A) AC Adapter
Case
NA
Cooling
Standard
Keyboard
Standard
Mouse
Synaptics TouchPad
Internet Speed
Charter Communications Cable Internet - 20m Down 3m Up
Back
Top