I need to get working properly a tiny Windows batch file (convert.cmd) that changes bitrate of all MP3 files in a specified folder. I need to pass 2 parameters to the batch file:
the path to the folder with MP3 files
bitrate I want to change them to.
I am using Lame.exe encoder. The lame.exe is in one place, convert.cmd can be in the same folder with lame.exe, but the folder with MP3 files can be anywhere. The original version (without parameters) was (and it's working fine if I place convert.cmd in the folder wit MP3 files):
#ECHO OFF
FOR %%f IN (*.mp3) DO (
D:\Apps\Lame\lame.exe -h -b 128 "%%f" "%%f.temp"
DEL "%%f"
REN "%%f.temp" "%%f"
)
PAUSE
Instead of 128 I need to pass "%2" and it will be a second command-line parameter, the bitrate, and for MP3 files folder path I need to pass "%1". So, I got this, but it's not working.
#ECHO OFF
FOR %%f IN (%1\*.mp3) DO (
D:\Apps\Lame\lame.exe -h -b %2 "%%f" "%%f.temp"
DEL "%%f"
REN "%%f.temp" "%%f"
)
PAUSE
How to make it work as described?
How can I ensure that my batch file convert existing files, and not creating new converted copies of them somewhere? Thanks a bunch ;) Cheers.
UPDATE
The location of convert.cmd is:
d:\Apps\Lame\convert.cmd, same folder with lame.exe
The location of MP3 files is:
d:\temp\xxx\
File1.mp3
File2.mp3
When I execute convert.cmd from the command line like this:
convert.cmd d:\temp\xxx\ 64
what I get in d:\temp\xxx\ is this:
File1.mp3.temp
File2.mp3.temp
Where did the converted files go?
Thanks.
Thanks, I have already figured out how to write this script.
If someone needs this type of conversion, here we go:
1 param - full path to the folder with mp3 files
2 param - bitrate to convert to
(remember, lame.exe does not preserve mp3 tags)
p.s. who needs mp3 tags anyways ? :)
#ECHO OFF
ECHO.
ECHO BEGIN CONVERSION
ECHO.
CD %1
DIR *.mp3
ECHO -------------------------------------------------------------------------------
ECHO THESE MP3 FILES WILL BE CONVERTED TO BITRATE %2 KBPS
ECHO -------------------------------------------------------------------------------
PAUSE
FOR %%f IN (*.mp3) DO (
ECHO -------------------------------------------------------------------------------
ECHO CONVERTING: %%f
ECHO -------------------------------------------------------------------------------
D:\Apps\Lame\lame.exe -h -b %2 "%%f" "%%~nf.wav"
DEL "%%f"
REN "%%~nf.wav" "%%f"
)
ECHO.
ECHO END CONVERSION
ECHO.
PAUSE
Related
I have about 60 files to unzip as you can see below:
I know the 7zip option, which can unzip all of them, but the problem is, that the file inside doesn't match the zip directory name, which would be highly desirable here.
I found some solutions for the batch file here:
https://superuser.com/questions/371384/extract-all-zips-in-a-directory-incl-subfolders-with-a-bat-file-or-dos-comm
and prepared some batch code for this which looks like this:
#echo off
setlocal
cd /d %~dp0
for %%a in (*.zip) do (
Call :UnZipFile "C:\my\Desktop current\Occ KMZ\bat\Aldebaran" "C:\my\Desktop current\Occ KMZ\bat\Aldebaran"
)
exit /b
but it doesn't work at all. I can neither unzip it nor get files.
The 7zip software has a few options, which potentially could be good
but I don't know how to use the 7Zip command line in order to get the unzipped file with the same name as the zip directory.
What should I do to automatize this section?
Here's something (minimal) that should work. Some parts can be done better (error handling and so on). It unzips each archive into a dir named like the archive but without the (.zip) extension.
script00.bat:
#echo off
setlocal enableextensions enabledelayedexpansion
set EXE_7Z="c:\Install\pc064\7Zip\7Zip\Version\7z.exe"
for %%g in ("%~dp0*.zip") do (
call :unpackFile "%%g"
)
goto :done
:unpackFile
set _ARCH_DIR="%~dp1%~n1"
rmdir /q /s %_ARCH_DIR% 2>nul
%EXE_7Z% x -o%_ARCH_DIR% %1 >nul 2>&1
goto :eof
:done
echo Done.
goto :eof
Output:
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow]> sopr.bat
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###
[prompt]> tree /a /f q071380369
Folder PATH listing for volume SSD0-WORK
Volume serial number is 00000068 AE9E:72AC
E:\WORK\DEV\STACKOVERFLOW\Q071380369
file00.zip
file01.zip
script00.bat
No subfolders exist
[prompt]> q071380369\script00.bat
Done.
[prompt]> tree /a /f q071380369
Folder PATH listing for volume SSD0-WORK
Volume serial number is 0000006E AE9E:72AC
E:\WORK\DEV\STACKOVERFLOW\Q071380369
| file00.zip
| file01.zip
| script00.bat
|
+---file00
| kkt.py
|
\---file01
URLs.txt
I'm having a little problem for compressing multiples files.
The problem is, if the file name is the same even not in the same folder, they are automatically compressing.
Here's the example of what I'm talking about.
Folder 1:
JOHN 1.psd
JOHN 2.psd
Folder 2
JOHN 1.psd
JOHN 2.psd
The problem output become like this, JOHN 1.psd.rar
and inside of that file, there is JOHN 1.psd, (from folder 1), and JOHN 1.psd, (from folder 2).
I want, to compress them in the same source folder even the same file from different folder. Because I'm doing so many files to compress.
Here's my script:
#echo off
:start
cls
set path="C:\Program Files\WinRAR\Rar.exe"
set ext=psd
echo.
#echo off
for /r %%A in (*.%ext%) do (
%path% a -r -ep -df "%%A.rar" "%%~nxA"
)
exit
Here's my solution:
#echo off
:start
cls
set WinrarDir="C:\Program Files\WinRAR\Rar.exe"
echo.
#echo off
for /r %%i in (*.psb) do (
%WinrarDir% a -r -ep -df "%%i.rar" "%%i"
)
exit
I have started a huge video project which I am trying to automate. So far, I made good progress, but now I am stuck. I have searched in Google and here, in Stack OverFlow for answers, but can’t find the solution to my problem.
For completion I will explain my full project.
First step of my project is to convert all of my files to *.mp4 and in the same run burn my logo and website in the video. I do this with this code:
for %%a in ("*.*") do ffmpeg -i "%%a" -i "C:\Users\PC03\Desktop\Video test\Overlay.png" -filter_complex "[0:v][1:v] overlay" -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 128k "newfiles\%%~na.mp4"
pause
After that, I will place all the video files in their relevant subfolder. This way I have almost a hundred subfolders, with 2 or 3 files in them. Per submap I want a video with an intro (not in the submap) the video’s in the submap, and an outro (not in the submap).
I can do the above with this code:
ffmpeg -f concat -i intro.mp4 -i mylist.txt -outro.png -c copy total.mp4
To automate everything, I have this code to make a mylist.txt file per subfolder:
>output.txt (
echo C:\Users\PC03\Desktop\Video test\vast\intro.mp4
(for %%i in (*.mp4) do #echo file '%%i')
echo C:\Users\PC03\Desktop\Video test\vast\outro.mp4
)
Now the only thing which I have to do is automate the following code:
ffmpeg -f concat -i intro.mp4 -i mylist.txt -outro.png -c copy total.mp4
to go through all the subfolders.
I have made this code:
FOR /R "C:\Users\PC03\Desktop\Video test" %%F IN (.) DO (
> %%F\output.txt (
echo "C:\Users\PC03\Desktop\Video test\vast\intro.mp4"
(for %%i in (*.mp4) do (
#echo file '%%i'
))
echo "C:\Users\PC03\Desktop\Video test\vast\outro.mp4"
)
)
This codes provides me with a mylist.txt file in every subfolder, but the content is not what I want. It takes the content of the parentmap instead of the subfolders. I have a strong feeling that somewhere in this code I have to make another FOR /R but I can’t make it work.
Does someone have a suggestion on how to do this?
The FOR /R will iterate the folders but you try to iterate the *.mp4 files without referring to the currently processed (sub)folder.
#Echo off
Set "Base=C:\Users\PC03\Desktop\Video test"
Set "Ext=*.mp4"
FOR /R "%Base%" %%F IN (.) DO (
PushD "%%F"
if exist "%Ext%" (
> "%%~fF\output.txt" (
echo "%Base%\vast\intro.mp4"
For %%I in (%Ext%) do #echo file '%%~fI'
echo "%Base%\vast\outro.mp4"
)
Echo created "%%~fF\output.txt"
)
PopD
)
I have an application which saves files to a FTP folder that I sync to my PC which contains multiple JPG and MP4 files, named in the following format:
ARC20170510151547.jpg
ARC20170510151549.mp4
What I'm trying to do is:
Copy the files from my FTP to my PC
Sort the files into folders based on the day they were created
Delete files from the FTP older than 14 days
Delete files from the PC older than 1 month
Using WinSCP to connect to FTP with the following code, I am able to download all the files to my local drive:
"c:\program files (x86)\winscp\winscp.com" /ini=nul /command ^
"open ftp://[username]:[password]#[ipaddress]/" ^
"synchronize local f:\[localpath]\ /[remotepath]/ " ^
"exit"
Then I need to sort the files. Here is where I am stuck. I'm think I know the commands but I am unsure how to use the 'tokens' and 'delims' to get it to work how I want.
#echo
for %%a in (*.*) do (
echo processing "%%a"
for /f "tokens=1 delims=" %%a in ("%%~nxa") do (
md "%%b-%%c" 2>nul
move "%%a" "%%b-%%c" >nul
)
)
pause
As I know the filename format isn't going to change, one thing I have considered is adding some special characters to the filename, maybe using the 'ren' command. I could then use those special characters as search delims but, again, I'm struggling how to best proceed.
Removing local files older than 30 days is easy using the following script
forfiles -p "f:\[localpath]" -s -m *.* -d <number of days> -c "cmd /c del #path"
However, the WinSCP 'RM' command I am using doesn't appear to be working. It returns an error "no file matching '*<14D' found"
"rm /[filepath]/*<14D" ^
Any help, advice and guidance would be very gratefully received!
Since there is no delimiter between the date elements you need substrings,
substrings do only work with normal variables and in a (code block) you need delayed expansion
It's unclear if you want folders with year-month or month-day, select the proper part in the batch and comment/uncomment the Rem:
With extensions enabled md can create the structure YY-MM\DDin one step.
So you can move directly to that folder.
#Echo off&SetLocal EnableExtensions EnableDelayedExpansion
for %%a in (ARC*.*) do (
echo processing "%%a"
Set File=%%~nA
Set YY=!File:~3,4!
Set MM=!File:~7,2!
Set DD=!File:~9,2!
Rem YY-MM\DD
md "!YY!-!MM!\!DD!" 2>nul
move "%%a" "!YY!-!MM!\!DD!" >nul
)
pause
#LotPings! Thank you for the script. This does almost what I want it to do. I have modified the script as below which moves the files into folders based on the Day.
So, each day, maybe 100 - 200 files are generated. So I do not mind having a folder for each day. Once the files are moved into their respective "Day" folder, what I'd then like to do is create a SubFolder "!YY!-!MM!" and then move the "!DD!" Folders into the "!YY!-!MM!" folder.
#Echo off&SetLocal EnableExtensions EnableDelayedExpansion
for %%a in (ARC*.*) do (
echo processing "%%a"
Set File=%%~a
Set YY=!File:~3,4!
Set MM=!File:~7,2!
Set DD=!File:~9,2!
md "!DD!" 2>nul
md "!YY!-!MM!" 2>nul
move "%%a" "!DD!" >nul
)
pause
I wrote some simple batch file that converts any audio/video files to .ogg (audio) format. For example music off youtube which is in .flv format. Here's the script:
set ogg_rate=1.3
set source_dir=f:\music
set dest_dir=f:\music\out
set my_temp=f:\temp
Rem Go to source dir
cd /d %source_dir%
for %%f in (*.*) do (
Rem Extract audio from avi file using ffmpeg
c:\encode\ffmpeg.exe -i "%source_dir%\%%f" "%my_temp%\%%f.wav"
rem Encode the audio with OGG encoder using 1.3 quality setting
cd /d %my_temp%
c:\encode\oggenc2.exe -q %ogg_rate% -o "%dest_dir%\%%f.ogg" "%my_temp%\%%f.wav"
rem delete all temp files
cd /d %my_temp%
del *.* /q
)
It works file, but I cannot figure out how to remove the unnecessary extension.
For example, if the input file is file.flv then after converting to wave it will be file.flv.wav, then after converting it to .ogg it will be file.flv.ogg.
How to get the file.ogg (without .flv)
BTW: instead of .flv it can be .mp4, .avi or another extension.
In your for statement, try using %%~nf instead of %%f. For statements in batch files have a lot of substitution options you can utilize:
for %%R in (*.*) do (
#echo %%~nR
)