Building a batch to read info from txt and decide what to do with a video file [closed] - batch-processing

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
THIRD DAY!
New output file txt:
Filename : %FILENAME%.%EXTENSION%
Sizes : 1.66 GiB for 1h 58mn 0s 615ms at 2 014 Kbps
Writing_App : VirtualDubMod 1.5.10.2 (build 2542/release)
Video_#0 : DivX 5 MPEG-4 Visual at 1 812 Kbps, with 1.49 GiB (90%)
Aspect : 704 x 368 (1.913) at 23.976 fps
Writing_App_V : DivX 6.8.5 (UTC 2009-08-20)
Audio_#0 : AC3
Mode_#0 : Constant
Sample_#0 : 48000
Channels_#0 : 2
Size_#0 : 162 MiB (10%)
Title_#0 :
Audio_#1 : MP3
Mode_#1 : Constant
Sample_#1 : 44100
Channels_#1 : 2
Size_#1 : 101 MiB (11%)
Title_#1 :
rem Required to use Delayed !Variable! Expansion
setlocal EnableDelayedExpansion
rem Create all text files (copied from your example)
rem for %%T in ("*.avi") do "C:\Meus Programas\MEDIA\MediaInfo CLI\MediaInfo.exe" --output=file://"C:\Meus Programas\MEDIA\MediaInfo CLI\luis4.csv" --logfile="%%~nT.cod" "%%T"
rem echo.>TXTCollector.lst
rem for %%Z in ("*.cod") do type "%%~Z">>TXTCollector.lst && echo ===========================================>>TXTCollector.lst && echo.>>TXTCollector.lst
rem ren TXTCollector.lst TXTCollector.txt
rem Process each file
for %%F in (*.cod) do (
rem Delete variables that may not exist in certain files
set Audio_#1=
rem Read variables from this text file (explained above)
for /F "usebackq tokens=1* delims=:" %%a in ("%%F") do (
for %%c in (%%a) do set %%c=%%b
set %%c=!%%c:~1!
)
ECHO VirtualDub.Open("r:\\%%~nF.avi","",0);>"%%~nF.vcf"
ECHO VirtualDub.RemoveInputStreams();>>"%%~nF.vcf"
)
Writed all the bat file and started to debug. My first two lines started a problem. This batch is to create a script file (.vcf) and the Redirection with >> is not working anymore.
ECHO VirtualDub.Open("r:\%%~nF.avi","",0);>"%%~nF.vcf"
Created a file with the name correct with the parameter %%~nF.vcf but flushed inside the file all the work done by
for /F "usebackq tokens=1* delims=:" %%a in ("%%F")
ECHO VirtualDub.RemoveInputStreams();>>"%%~nF.vcf" generated a file called %~nF.vcf (this means that the parameter doesnt work anymore.)
Tried to switch off EnableDelayedExpansion, same results. Maybe its because the brackets.
Stuck Again!
SECOND DAY!
OK, #Aacini, thanks... Will try to resume...
I Have a lot of files to work with... I generate a .txt for every file. I'm trying to do a batch that reads each .txt and decides what to do with the original file.
TXT FILES:
General
ORIGINAL_FILENAME.avi
818 MiB for 1h 46mn 25s 14ms
AVI-Mux GUI 1.16.11, Dec 15 2004 14:51:34
Video #0
XviD MPEG-4 Visual, with 624 MiB (76%), at 23.976 fps
XviD 1.2.1 (UTC 2008-12-04)
Audio #0
MPEG Audio Version 1 Layer 3
Variable
44.1 KHz
2 channels
85.8 MiB (10%)
Portuguese BR - 3LT0N
LAME3.93a
Audio #1
MPEG Audio Version 1 Layer 3
Variable
48.0 KHz
2 channels
97.5 MiB (12%)
English - 3LT0N
LAME3.98r
The batch i've been thinking so far...
IF DOESNT EXIST "Audio #1" in TXT goto :ONEAUDIO
IF EXIST "AC-3" in TXT goto :AC3
Set Value 0 from txt line 02 = filename
"for audio 1"
Set Value 1 from txt line 12 = Variable OR Constant
Set Value 2 from txt line 13 = 44.1 OR 48.0
"for audio 2"
Set Value 3 from txt line 21 = Variable or Constant
Set Value 4 from txt line 22 = 44.1 or 48.0
if value 1 = variable goto :variable1 ELSE goto :constant1
:variable1
(will execute some commands here)
if value 2 = 44.1 goto :22 ELSE goto :24
:22
(will execute some commands here)
goto :jump24
:24
(will execute some commands here)
:jump24
if value 3 = variable goto :variable2 ELSE goto :constant2
:variable2
(will execute some commands here)
if value 4 = 44.1 goto :44 ELSE goto :48
:44
(will execute some commands here)
goto :end
:48
(will execute some commands here)
goto :end
:constant1
(will execute some commands here)
goto :end
:constant2
(will execute some commands here)
goto :end
:ONEAUDIO
later
goto :end
:AC3
later
goto :end
:end
This will run in some trouble... I only know something about FOR (LOOP) and as far as I know it can not work with GOTO :EXAMPLE. Maybe work using two batch files... a loop for calling the second batch parsing the filename.txt
Another way I was thinking is the batch generate a "batch model" for every videofile, then read the .txt for the videofile, then replacing strings in the "batch model". But this is too advanced for me.
FIRST DAY:
I need help to join my batch files into just one and add the ability to this batch to read a file .txt and decide the next steps for a bunch of videos in the same dir. It's all about of converting audio from avi to generate compatibility to editing programs...
The steps are:
1) Generate a .txt for every video file with the basic info about the video and audio.
for %%a in ("*.avi") do "C:\Meus Programas\MEDIA\MediaInfo CLI\MediaInfo.exe" --output=file://"C:\Meus Programas\MEDIA\MediaInfo CLI\luis.csv" --logfile="%%~na.txt" "%%a"
or generate a large file with all the small ones:
for %%a in ("*.avi") do "C:\Meus Programas\MEDIA\MediaInfo CLI\MediaInfo.exe" --output=file://"C:\Meus Programas\MEDIA\MediaInfo CLI\luis.csv" --logfile="%%~na.txt" "%%a"
echo.>TXTCollector.lst
for %%i in ("*.txt") do type "%%~i">>TXTCollector.lst && echo ===========================================>>TXTCollector.lst && echo.>>TXTCollector.lst && del "%%~i"
ren TXTCollector.lst TXTCollector.txt
OUTPUT FILE EXAMPLE:
General : ORIGINAL NAME FOR THE VIDEO FILES.avi
Format : 820 MiB for 1h 26mn 38s 777ms at 1 324 Kbps
Writing App. : VirtualDubMod 1.5.10.2 (build 2540/release)
Video #0 : XviD MPEG-4 Visual at 925 Kbps, with 574 MiB (70%)
Aspect : 608 x 336 (16:9) at 23.976 fps
Writing App. : XviD 1.2.1 (UTC 2008-12-04)
Audio #0 : 119 MiB (15%), AC-3 ,
Infos : Constant at 192 Kbps, 48.0 KHz, 1 channel
Writing App. : ,
Audio #1 : 110 MiB (12%), MPEG Audio Version 1 Layer 3,
Infos : Constant at 128 Kbps, 48.0 KHz, 2 channels
Writing App. : LAME3.97 , -m j -V 4 -q 2 -lowpass 17 -b 128
2) From there, reading the audio formats from files, I move the files to the specific folder and execute the batch in that folder to run the conversion.
Example to the bats.
REM #echo off
:: create the virtual drives and go to the root of drive r:
set ORIGINALDIR=%~d0
subst r: "%cd%"
md JobDone
subst s: "%cd%\JobDone"
r:
cd\
for %%w in ("*.avi") do ECHO VirtualDub.Open("r:\\%%~w","",0);>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.RemoveInputStreams();>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[0].SetSource(0x73647561,0,1);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[0].DeleteComments(1);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[0].AddComment(0x00000003,"","Portuguese");>>"%%~nw.vcf"
REM for %%w in ("*.avi") do ECHO VirtualDub.stream[0].AddComment(0x00000003,"","English");>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[0].AdjustChapters(1);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[0].SetMode(1);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[0].SetInterleave(1,500,1,0,0);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[0].SetClipMode(1,1);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[0].SetConversion(0,0,0,0,0);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[0].SetVolume();>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[0].SetCompression(85,48000,2,0,16000,1,12,"AQAEAAAAgAEBAAAA");>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[0].EnableFilterGraph(0);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[0].filters.Clear();>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[1].SetSource(0x73647561,1,1);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[1].DeleteComments(1);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[1].AddComment(0x00000003,"","English");>>"%%~nw.vcf"
REM for %%w in ("*.avi") do ECHO VirtualDub.stream[1].AddComment(0x00000003,"","Portuguese");>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[1].AdjustChapters(1);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[1].SetMode(1);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[1].SetInterleave(1,500,1,0,0);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[1].SetClipMode(1,1);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[1].SetConversion(0,0,0,0,0);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[1].SetVolume();>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[1].SetCompression(85,48000,2,0,16000,1,12,"AQAEAAAAgAEBAAAA");>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[1].EnableFilterGraph(0);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.stream[1].filters.Clear();>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.video.DeleteComments(1);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.video.AddComment(0x00000002,"ISFT","VirtualDubMod 1.5.10.2 (build 2542/release)");>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.video.AdjustChapters(1);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.video.SetDepth(24,24);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.video.SetMode(0);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.video.SetFrameRate(0,1);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.video.SetIVTC(0,0,-1,0);>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.video.SetCompression();>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.video.filters.Clear();>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.SaveAVI("s:\\%%~nw.avi");>>"%%~nw.vcf"
for %%w in ("*.avi") do ECHO VirtualDub.Close();>>"%%~nw.vcf"
:: Execute the script file just created
for %%a in ("*.vcf") do "C:\VirtualDubMod\VirtualDubMod.exe" /r /s"%%~fa" /x && del "%%~fa"
:: go back to previous folder and delete the virtual drives.
%ORIGINALDIR%
REM %~d0
subst r: /d
subst s: /d
:end
I have a folder and a batch for each job. Basically it's 3 different process:
Video files with AC3 audio needs a different approach...
Video files with MP3 converting everything to a constant bitrate and 48000 sampling rate.
Video files with already constante bitrate don't need converting but just a remux.
ONE AUDIO
+AC3 AUDIO
--2 CHANNELS
--6 CHANNELS
+MP3 AUDIO
--44100 SAMPLING RATE
--48000 SAMPLING RATE
+JUST REMUX AUDIO
TWO AUDIOS
+AC3
--2ch-2ch
--2ch-6ch
--6ch-2ch
--6ch-6ch
+1ST AUDIO ONLY
--44100
--48000
+2ND AUDIO ONLY
--44100
--48000
+44100-44100
+44100-48000
+48000-41000
+48000-48000
+INVERT AUDIO (just change the order of the audio tracks, no converting)
+JUST REMUX
This Is Where The Fun Begins:
Video files with just one audio is rare... can stay out of the batch.
If... there was one bat file to do it all... then the LOOP for (*.avi) will not work anymore, because every video file has it's own properties... then again... the batch will have to create the script (or a new bat to create the script) based on the filename.
Audio #0 : 119 MiB (15%), AC-3 ,
Infos : Constant at 192 Kbps, 48.0 KHz, 1 channel
Writing App. : ,
Just thinking about... if it was just one audio... then:
has ac3 (has 2ch do 2 channel conversion; if not do 6 channel conversion)
if not ac3 (has constant -> just remux -> else (if 48.0 do 48.0 conversion; else do 41000 conversion)
It's "quite simple"
But the files have two audios.... now it's very difficult to me.
Audio #0 : 119 MiB (15%), AC-3 ,
Infos : Constant at 192 Kbps, 48.0 KHz, 1 channel
Writing App. : ,
Audio #1 : 110 MiB (12%), MPEG Audio Version 1 Layer 3,
Infos : Constant at 128 Kbps, 48.0 KHz, 2 channels
Writing App. : LAME3.97 , -m j -V 4 -q 2 -lowpass 17 -b 128
Let me explain somethings:
"Just remux" and "MP3s conversions" use the internal audio from video file. "AC3 conversion" is not that simple. Must pull out the audio from file, do the 1st conversion with other app, then do the second conversion in the original program.
md audio1
for %%x in ("*.avi") do "C:\VirtualDubMod\ffmpeg.exe" -i "%%x" -vn -map 0:1 -acodec copy "%%~dpxaudio1\%%~nx.audio1.ac3"
md audio2
for %%u in ("*.avi") do "C:\VirtualDubMod\ffmpeg.exe" -i "%%u" -vn -map 0:2 -acodec copy "%%~dpuaudio2\%%~nu.audio2.ac3"
cd audio1
for %%y in ("*.ac3") do "c:\Meus Programas\AUDIO\BeSweet\BeSweet.exe" -core( -input "%%~fy" -output "%%~dpy%%~ny.wav" -2ch ) -azid( -c light ) -ota( -hybridgain ) && del "%%~y"
cd..
cd audio2
for %%y in ("*.ac3") do "c:\Meus Programas\AUDIO\BeSweet\BeSweet.exe" -core( -input "%%~fy" -output "%%~dpy%%~ny.wav" -2ch ) -azid( -c light -L -3db ) -ota( -hybridgain ) && del "%%~y"
The script generated for the conversion can be broken into pieces:
1) video file to be processed
2) 1st audio and options to convession
obs: mp3 (don't need to specify a file, it's a code for internal audio) AC3 (have to specify the .wav filename)
3) 2nd audio and options to conversion
4) video and options to conversion
5) filename to save new file
6) command to close the app at the end of process.
The batch can create a script (or a new batch to generate the script) pasting these peaces one by one. and the batch can have a "catalogue" of pieces and choose the right one by the info about the audio....
It's this possible?

Ok. I will try to get something clear from all this mess...
You show us two different formats for the text file. The first one (under OUTPUT FILE EXAMPLE) is easier to process. I suppose that you may modify this file so the headings of each line be unique and have not spaces by inserting underscores or numbers (to be valid Batch variable names). This is your example file in the format required by my program:
General : ORIGINAL NAME FOR THE VIDEO FILES.avi
Format : 820 MiB for 1h 26mn 38s 777ms at 1 324 Kbps
Writing_App : VirtualDubMod 1.5.10.2 (build 2540/release)
Video_#0 : XviD MPEG-4 Visual at 925 Kbps, with 574 MiB (70%)
Aspect : 608 x 336 (16:9) at 23.976 fps
Writing_App_V0 : XviD 1.2.1 (UTC 2008-12-04)
Audio_#0 : 119 MiB (15%), AC-3 ,
Infos_A0 : Constant at 192 Kbps, 48.0 KHz, 1 channel
Writing_App_A0 : ,
Audio_#1 : 110 MiB (12%), MPEG Audio Version 1 Layer 3,
Infos_A1 : Constant at 128 Kbps, 48.0 KHz, 2 channels
Writing_App_A1 : LAME3.97 , -m j -V 4 -q 2 -lowpass 17 -b 128
The following code will read previous file and define the variables of the left side of the colon with the values of the right side:
rem Read each line from the text file
for /F "tokens=1* delims=:" %%a in (thefile.txt) do (
rem Eliminate spaces from variable name
for %%c in (%%a) do set %%c=%%b
rem Eliminate first character (space) from variable value
set %%c=!%%c:~1!
)
After previous loop ends you may directly get the vale of each variable. For example, ECHO !Format! or IF NOT DEFINED Audio_#1 ECHO One Audio or IF "!Audio_#0:AC-3=!" EQU "!Audio_#0!" ECHO Audio #0 is NOT AC-3", etc.
This is a first attempt to put all pieces together:
#echo off
rem Required to use Delayed !Variable! Expansion
setlocal EnableDelayedExpansion
rem Create all text files (copied from your example)
for %%a in ("*.avi") do "C:\Meus Programas\MEDIA\MediaInfo CLI\MediaInfo.exe" --output=file://"C:\Meus Programas\MEDIA\MediaInfo CLI\luis.csv" --logfile="%%~na.txt" "%%a"
rem Process each file
for %%f in (*.txt) do (
rem Delete variables that may not exist in certain files
set Audio_#1=
rem Read variables from this text file (explained above)
for /F "usebackq tokens=1* delims=:" %%a in ("%%f") do (
for %%c in (%%a) do set %%c=%%b
set %%c=!%%c:~1!
)
rem Identify each case
set AC-3=NO
if "!Audio_#0:AC-3=!" neq "!Audio_#0!" set AC-3=YES
if not defined Audio_#1 (
rem One Audio
if !AC-3! equ YES (
rem Process One Audio with AC-3
) else (
rem Process One Audio with no AC-3
)
) else (
rem Two Audios
if "!Audio_#1:AC-3=!" neq "!Audio_#1!" set AC-3=YES
if !AC-3! equ YES (
rem Process Two Audios with AC-3
) else (
rem Process Two Audios with no AC-3
)
)
)
Try to understand this code and do several tests, then post your new questions.
Antonio
ADDENDUM: Explanation on "Eliminate spaces from variable name"
If this FOR command:
for /F "tokens=1* delims=:" %%a in (thefile.txt) do (
set %%a=%%b
)
read this line:
General : ORIGINAL NAME FOR THE VIDEO FILES.avi
then the executed SET command is this:
set General = ORIGINAL NAME FOR THE VIDEO FILES.avi
This way, the variable name is precisely "General<11 spaces>", so
echo %General% does NOT work
echo %General % OK
To avoid this mess, spaces from variable name must be deleted.
You must know that if you execute this command:
for %%a in ( one two threee ) do echo "%%a"
the result is:
"one"
"two"
"three"
So a FOR command may be used to eliminate spaces. OK?

The batch is working, and tested against all kind of files. Thanks for all the help. This batch is doing what was intended for, but it has some work to do. It can be cleaned a lot. Later...
#echo off
rem create the virtual drives needed to VirtualDubMod work
set ORIGINALDRIVE=%~d0
subst r: "%cd%"
md JobDone
subst s: "%cd%\JobDone"
r:
cd\
rem Required to use Delayed !Variable! Expansion
setlocal EnableDelayedExpansion
rem Create all text files (copied from your example)
for %%T in ("*.avi") do "C:\Meus Programas\MEDIA\MediaInfo CLI\MediaInfo.exe" --output=file://"C:\Meus Programas\MEDIA\MediaInfo CLI\luis4.csv" --logfile="%%~nT.cod" "%%T"
rem Create "catalogue" from all INFOs created.
echo.>TXTCollector.lst
for %%Z in ("*.cod") do type "%%~Z">>TXTCollector.lst && echo ===========================================>>TXTCollector.lst && echo.>>TXTCollector.lst
ren TXTCollector.lst TXTCollector.txt
rem Process each file
for %%F in (*.cod) do (
rem Setting the variables needed!
set NAMEFILE=%%~nF
rem Delete variables that may not exist in certain files
set Audio_#1=
rem Read variables from this text file (explained above)
for /F "usebackq tokens=1* delims=:" %%a in ("%%F") do (
rem Eliminate spaces from variable name?????????
for %%c in (%%a) do (
set %%c=%%b
rem Eliminate first character (space) from variable value
set %%c=!%%c:~1!
)
)
ECHO VirtualDub.Open^("r:\\!NAMEFILE!.avi","",0^);>"!NAMEFILE!.vcf"
ECHO VirtualDub.RemoveInputStreams^(^);>>"!NAMEFILE!.vcf"
rem PROCESS FIRST AUDIO
if !Audio_#0! equ AC3 (
rem PROCESS AC3
if !Channels_#0! equ 6 (
rem Process AC3 6 Channels
ECHO -=-=-=-=-=-=-=-=-=-=-
ECHO AC3_1 HAS 6 CHANNELS
ECHO -=-=-=-=-=-=-=-=-=-=-
"C:\VirtualDubMod\ffmpeg.exe" -i "!NAMEFILE!.avi" -vn -map 0:1 -acodec copy "r:\!NAMEFILE!.audio1.ac3"
"c:\Meus Programas\AUDIO\BeSweet\BeSweet.exe" -core^( -input "r:\!NAMEFILE!.audio1.ac3" -output "r:\!NAMEFILE!.audio1.wav" -2ch ^) -azid^( -c light -L -3db ^) -ota^( -hybridgain ^)
del "r:\!NAMEFILE!.audio1.ac3"
) else (
rem Process AC3 2 or 1 Channels
ECHO -=-=-=-=-=-=-=-=-=-=-
ECHO AC3_1 HAS 2 CHANNELS
ECHO -=-=-=-=-=-=-=-=-=-=-
"C:\VirtualDubMod\ffmpeg.exe" -i "!NAMEFILE!.avi" -vn -map 0:1 -acodec copy "r:\!NAMEFILE!.audio1.ac3"
"c:\Meus Programas\AUDIO\BeSweet\BeSweet.exe" -core^( -input "r:\!NAMEFILE!.audio1.ac3" -output "r:\!NAMEFILE!.audio1.wav" -2ch ^) -azid^( -c light ^) -ota^( -hybridgain ^)
del "r:\!NAMEFILE!.audio1.ac3"
)
ECHO VirtualDub.stream[0].SetSource^("r:\\!NAMEFILE!.audio1.wav",0x00000201^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].DeleteComments^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].AddComment^(0x00000003,"","Portuguese"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].AdjustChapters^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetMode^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetInterleave^(1,500,1,0,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetClipMode^(1,1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetConversion^(0,0,0,0,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetVolume^(^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetCompression^(85,48000,2,0,16000,1,12,"AQAEAAAAgAEBAAAA"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].EnableFilterGraph^(0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].filters.Clear^(^);>>"!NAMEFILE!.vcf"
) else (
rem PROCESS MP3
if !Mode_#0! equ Constant (
rem JUST REMUX AUDIO
ECHO VirtualDub.stream[0].SetSource^(0x73647561,0,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].DeleteComments^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].AddComment^(0x00000003,"","Portuguese"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].AdjustChapters^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetMode^(0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetInterleave^(1,500,1,0,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetClipMode^(1,1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetConversion^(0,0,0,0,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetVolume^(^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetCompression^(^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].EnableFilterGraph^(0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].filters.Clear^(^);>>"!NAMEFILE!.vcf"
) else (
rem REDO AUDIO
ECHO VirtualDub.stream[0].SetSource^(0x73647561,0,1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].DeleteComments^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].AddComment^(0x00000003,"","Portuguese"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].AdjustChapters^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetMode^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetInterleave^(1,500,1,0,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetClipMode^(1,1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetConversion^(0,0,0,0,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetVolume^(^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].SetCompression^(85,48000,2,0,16000,1,12,"AQAEAAAAgAEBAAAA"^);>>"!NAMEFILE!.vcf"
if !Sample_#0! equ 44100 (
rem REDO 44100 AUDIO
ECHO VirtualDub.stream[0].EnableFilterGraph^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].filters.Clear^(^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].filters.Add^("input"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].filters.Add^("resample"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].filters.Connect^(0, 0, 1, 0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].filters.instance[1].SetInt^(0, 48000^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].filters.instance[1].SetInt^(1, 64^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].filters.Add^("output"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].filters.Connect^(1, 0, 2, 0^);>>"!NAMEFILE!.vcf"
) else (
rem REDO 48000 AUDIO
ECHO VirtualDub.stream[0].EnableFilterGraph^(0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[0].filters.Clear^(^);>>"!NAMEFILE!.vcf"
)
)
)
rem PROCESS SECOND AUDIO
if !Audio_#1! equ AC3 (
rem PROCESS AC3
if !Channels_#1! equ 6 (
rem Process AC3 6 Channels
ECHO -=-=-=-=-=-=-=-=-=-=-
ECHO AC3_2 HAS 6 CHANNELS
ECHO -=-=-=-=-=-=-=-=-=-=-
"C:\VirtualDubMod\ffmpeg.exe" -i "!NAMEFILE!.avi" -vn -map 0:1 -acodec copy "r:\!NAMEFILE!.audio2.ac3"
"c:\Meus Programas\AUDIO\BeSweet\BeSweet.exe" -core^( -input "r:\!NAMEFILE!.audio2.ac3" -output "r:\!NAMEFILE!.audio2.wav" -2ch ^) -azid^( -c light -L -3db ^) -ota^( -hybridgain ^)
del "r:\!NAMEFILE!.audio2.ac3"
) else (
rem Process AC3 2 or 1 Channels
ECHO -=-=-=-=-=-=-=-=-=-=-
ECHO AC3_2 HAS 2 CHANNELS
ECHO -=-=-=-=-=-=-=-=-=-=-
"C:\VirtualDubMod\ffmpeg.exe" -i "!NAMEFILE!.avi" -vn -map 0:2 -acodec copy "r:\!NAMEFILE!.audio2.ac3"
"c:\Meus Programas\AUDIO\BeSweet\BeSweet.exe" -core^( -input "r:\!NAMEFILE!.audio2.ac3" -output "r:\!NAMEFILE!.audio2.wav" -2ch ^) -azid^( -c light ^) -ota^( -hybridgain ^)
del "r:\!NAMEFILE!.audio2.ac3"
)
ECHO VirtualDub.stream[1].SetSource^("r:\\!NAMEFILE!.audio2.wav",0x00000201^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].DeleteComments^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].AddComment^(0x00000003,"","English"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].AdjustChapters^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetMode^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetInterleave^(1,500,1,0,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetClipMode^(1,1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetConversion^(0,0,0,0,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetVolume^(^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetCompression^(85,48000,2,0,16000,1,12,"AQAEAAAAgAEBAAAA"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].EnableFilterGraph^(0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].filters.Clear^(^);>>"!NAMEFILE!.vcf"
) else (
rem PROCESS MP3
if !Mode_#0! equ Constant (
rem JUST REMUX AUDIO
ECHO VirtualDub.stream[1].SetSource^(0x73647561,1,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].DeleteComments^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].AddComment^(0x00000003,"","English"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].AdjustChapters^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetMode^(0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetInterleave^(1,500,1,0,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetClipMode^(1,1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetConversion^(0,0,0,0,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetVolume^(^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetCompression^(^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].EnableFilterGraph^(0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].filters.Clear^(^);>>"!NAMEFILE!.vcf"
) else (
rem REDO AUDIO
ECHO VirtualDub.stream[1].SetSource^(0x73647561,1,1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].DeleteComments^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].AddComment^(0x00000003,"","English"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].AdjustChapters^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetMode^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetInterleave^(1,500,1,0,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetClipMode^(1,1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetConversion^(0,0,0,0,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetVolume^(^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].SetCompression^(85,48000,2,0,16000,1,12,"AQAEAAAAgAEBAAAA"^);>>"!NAMEFILE!.vcf"
if !Sample_#0! equ 44100 (
rem REDO 44100 AUDIO
ECHO VirtualDub.stream[1].EnableFilterGraph^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].filters.Clear^(^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].filters.Add^("input"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].filters.Add^("resample"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].filters.Connect^(0, 0, 1, 0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].filters.instance[1].SetInt^(0, 48000^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].filters.instance[1].SetInt^(1, 64^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].filters.Add^("output"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].filters.Connect^(1, 0, 2, 0^);>>"!NAMEFILE!.vcf"
) else (
rem REDO 48000 AUDIO
ECHO VirtualDub.stream[1].EnableFilterGraph^(0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.stream[1].filters.Clear^(^);>>"!NAMEFILE!.vcf"
)
)
)
ECHO VirtualDub.video.DeleteComments^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.video.AddComment^(0x00000002,"ISFT","VirtualDubMod 1.5.10.2 (build 2542/release)"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.video.AdjustChapters^(1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.video.SetDepth^(24,24^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.video.SetMode^(0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.video.SetFrameRate^(0,1^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.video.SetIVTC^(0,0,-1,0^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.video.SetCompression^(^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.video.filters.Clear^(^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.SaveAVI^("s:\\!NAMEFILE!.avi"^);>>"!NAMEFILE!.vcf"
ECHO VirtualDub.Close^(^);>>"!NAMEFILE!.vcf"
"C:\VirtualDubMod\VirtualDubMod.exe" /r /s"R:\!NAMEFILE!.vcf" /x
rem del "!NAMEFILE!.vcf"
del "!NAMEFILE!.cod"
rem del "!NAMEFILE!.audio1.wav"
rem del "!NAMEFILE!.audio2.wav"
)
rem go back to original folder and delete the virtual drives.
%ORIGINALDRIVE%
subst r: /d
subst s: /d

Related

howto get totals from .bat math problem with integers?

Originally I had this file while it did work it required alot of extra work and was not the most effective or efficient way of doing so
#echo off
set /P x="Percentage:"
set /P y="Price:"
set /P Z="Fixed Rate:"
cscript //nologo calculate.vbs %x% %y% %z% > results.txt
set /P charge= < results.txt
pause
del results.txt
echo charge Fee Total: %charge%
cscript //nologo calculate2.vbs %y% %charge% > results2.txt
set /P total= < results2.txt
pause
del results2.txt
echo sale total amount: %total%
pause
after several steps in getting the results I was looking for a Stackoverflow member Gerhard was kind enough to help me with a more efficient and better way of coding what I was looking to achieve. However I am still missing one line of code that I can not figure out I am sure its simple but I do not fully understand how to do so ...
here is the code he was gracious enough to assist with
#echo off
if not exist "calculations.txt" call :setVars
if exist "calculations.txt" for /f "usebackq delims=" %%i in ("calculations.txt") do set "%%i"
echo fixed rate = %Z%
echo Percentage = %x%
choice /c CR /M "Continue or re-set?"
if errorlevel 2 call :setVars
for /f "usebackq delims=" %%i in ("calculations.txt") do set "%%i"
set /P "y=Price: "
for /F "delims=" %%i in ('powershell ((%x% / 100^)*%y% + %z%^)') do echo %%i
goto :EOF
:setVars
set /P "x=Percentage: "
set /P "Z=Fixed Rate: "x
(echo x=%x%
echo z=%z%
)>"calculations.txt"
the final piece of the puzzle I am looking for is how to also give the results of the equation at the end before the EOF and the original price ... so basically the value of do echo %%i + %y% to echo to the screen after the results of the equation before the EOF if anyone can assist or direct me on how I can add these I would be most grateful and Thank you in advance

How can the results of a pipeline be captured in a batch var without temp file?

Trying to get the number of disks in a system using diskpart without using a temp file. This works on the command line:
echo list disk | diskpart | find /C "Disk"
but I can't figure out how to redirect the result into a batch var. Of course the number printed by the above pipeline is higher due to labels, but they are constant (divide result by 3 for actual number of disks).
Any ideas?
I've tried:
set /A disks=<echo list disk...
set /A disks<echo list disk...
set /A disks= (echo list disk ...)
You need FOR F for capture the output of a program.
set "cmd=echo list disk | diskpart | find /C "Disk""
setlocal EnableDelayedExpansion
FOR /F "usebackq delims=" %%A in (`!cmd!`) do (
set var=%%A
)
echo !var!
You can do it with a batch file using WMIC like this:
#echo off
wmic logicaldisk get caption,providername,drivetype,volumename > ListDisk.txt
Start "" ListDisk.txt
pause
And if you want to echo the fixed drive like that :
#echo off
for /f "tokens=2" %%i in ('wmic logicaldisk where "drivetype=3" ^|find /i ":"') do (Set FixedDrive=%%i)
echo %FixedDrive%
pause

CMD: extract part of a filename and use it as variable

I ripped my CDs with EAC to CUE+WAV files, added cover art and all my files are in the same folder with filenames pattern "Album artist - Album title", for ex.:
Clannad - Legend.wav/cue/jpg
David Bowie - Best Of Bowie [Disc 1].wav/cue/jpg
David Bowie - Best Of Bowie [Disc 2].wav/cue/jpg
I'm new to this so I wrote a simple CMD batch to convert my music to FLAC format, but it requires manual copying and pasting of the actual wav/cue/jpg filenames and input of album artist, disc no. and total disc no. for their corresponding tags. It cannot be stored in cuesheet file for some reason, but in my case I have them in filenames as you can see above).
ECHO WAV/CUE/JPG FILENAME
SET /P "input="
ECHO ALBUMARTIST
SET /P "albumartist="
ECHO DISCNUMBER
SET /P "discnumber="
ECHO TOTALDISCS
SET /P "totaldiscs="
flac.exe -0 --picture="D:\Music\%input%.jpg" --tag-from-file="CUESHEET=D:\Music\%input%.cue" -T "ALBUMARTIST=%albumartist%" -T "DISCNUMBER=%discnumber%" -T "TOTALDISCS=%totaldiscs%" "D:\Music\%input%.wav"
My question is about automation of converting all my ripped albums. How can I extract album artist/disc no./total disc no. info from filenames and loop that for every .wav file?
#ECHO OFF
SETLOCAL
SET "destdir=U:\destdir"
PUSHD "%destdir%"
:: Find all .jpgs where there is a .wav and .cue with the same name
FOR /f "delims=" %%a IN ('dir /b /a-d *.jpg') DO IF EXIST "%%~na.wav" IF EXIST "%%~na.cue" (
FOR %%b IN (input albumartist discnumber totaldiscs) DO SET "%%b="
SET "input=%%~na"
FOR /f "delims=-" %%b IN ("%%a") DO SET "albumartist=%%b"
FOR /f "tokens=2delims=[]" %%b IN ("%%a") DO SET "disc=%%b"
IF DEFINED disc (
FOR /f "tokens=1delims=[]" %%d IN ("%%a") DO FOR /f %%c IN ('dir /b "%%d[*.wav"') DO SET /a totaldiscs+=1
)
CALL :gflac
)
POPD
GOTO :EOF
:gflac
:: remove trailing spaces from INPUT
IF "%albumartist:~-1%"==" " SET "albumartist=%albumartist:~0,-1%"&GOTO gflac
:: presume default for disc and totaldiscs
IF DEFINED disc (FOR /f "tokens=2" %%d IN ("%disc%") DO SET /a disc=%%d) ELSE (SET /a disc=1)
IF NOT DEFINED totaldiscs SET /a totaldiscs=1
ECHO( flac.exe -0 --picture="D:\Music\%input%.jpg" --tag-from-file="CUESHEET=D:\Music\%input%.cue" -T "ALBUMARTIST=%albumartist%" -T "DISCNUMBER=%discnumber%" -T "TOTALDISCS=%totaldiscs%" "D:\Music\%input%.wav"
GOTO :eof
You would need to change the setting of destdir to suit your circumstances.
The above will merely echo the required flac line. I left it as you posted but set the scant test data you posted up as I interpret it (ie. there is a set of 3 files) on my U: drive.
Sadly, you've given us insufficient information. I've assumed that you need all three files to be present, and the default for totaldiscs is 1.
First, look for all .jpgs, and if there is a corresponding .wav and .cue then process for flac generation as follows:
Set input to the name part of the .jpg found
set albumartist to the first part of the filename, up to the -
get the [disc n] string if it's present
count the number of .wavs that start with the filename up to the [
generate the flac line.
Within the generation of the flac line, we strip off the trailing spaces from input, convert disc n to n or set disc to 1 (although this information may not be needed), and set the totaldiscs to 1 if it's not been calculated.
You don't say what flac produces as output, but I'd suggest that you further gate that filetype so that the procedure doesn't run if the %input%.finalproductwhateverthatis file is present.
[edited per dbenham's comments]
This is very similar to Magoo's answer, with some bug fixes, and everything is done in one master loop without a CALL. As with Magoo's answer, modify your destination folder at the beginning to suit your needs.
#echo off
:: Delayed expansion must be disabled to protect ! when expanding FOR variables.
:: It is normally disabled by default, but I'm making it explicit, just to be sure.
setlocal disableDelayedExpansion
:: Define where source files are coming from
set "source=D:\Music"
:: Define where output should be stored
set "destination=D:\Music"
pushd "%destination%"
:: Iterate each .wav file (A) and only proceed if .jpg and .cue also exists
for /f "delims=" %%A in ('dir /b /a-d "%source%\*.wav"') do if exist "%source%\%%~nA.jpg" if exist "%source%\%%~nA.cue" (
%= Get base name with path, but without extension =%
set "file=%source%\%%~nA"
%= Extract "artist - album " (B) and "Disc #" (C) from base name (~nA) =%
for /f "delims=[] tokens=1,2" %%B in ("%%~nA") do (
%= Extract "artst " (D) from "artist - abum ". (~nxD) trims trailing space =%
for /f "delims=-" %%D in ("%%B") do set "artist=%%~nxD"
%= Extract the number (E) from "Disc #", use 1 as default if not there =%
set "disc=1"
for /f "tokens=2" %%E in ("%%C") do set "disc=%%E"
%= Count the number of discs (F), will be 0 if no [Disc #] =%
%= The [ is appended to name to prevent something like "Greatest Hits 2" from matching "Greatist Hits" =%
for /f %%F in ('dir /b /a-d "%source%\%%B[*.wav" 2^>nul ^|find /c /v ""') do set "count=%%F"
%= temporarily enable delayed expansion to access variables set within loop =%
setlocal enableDelayedExpansion
%= Set count to 1 if no [Disc #] =%
if !count! equ 0 set /a count=1
flac.exe -0 --picture="!file!.jpg" --tag-from-file="CUESHEET=!file!.cue" -T "ALBUMARTIST=!artist!" -T "DISCNUMBER=!disc!" -T "TOTALDISCS=!count!" "!file!.wav"
%= pop the setlocal stack to get back to state at beginning of loop =%
endlocal
)
)
popd
You may want to add a check to only proceed if the FLAC file does not already exist so you can run the script multiple times without reprocessing files. The outer loop would look something like this, but I can't be sure since I don't know the format of the output file name:
for /f "delims=" %%A in ('dir /b /a-d "%source%\*.wav"') do if exist "%source%\%%~nA.jpg" if exist "%source%\%%~nA.cue" if not exist "%destination%\%%~nA.flac" (
The logic is much simpler using my JREPL.BAT utility if you understand regular expressions:
#echo off
:: Delayed expansion must be disabled to protect ! when expanding FOR variables.
:: It is normally disabled by default, but I'm making it explicit, just to be sure.
setlocal disableDelayedExpansion
:: Define where source files are coming from
set "source=D:\music"
:: Define where output should be stored
set "destination=D:\music"
pushd "%destination%"
:: Iterate all *.wav and use JREPL to format result as "fullFileName|artist - album|artist|Disc#"
:: %%A %%B %%C %%D
:: Only proceed if .jpg and .cue also exist
for /f "tokens=1-4 delims=|" %%A in (
'dir /b /a-d "%source%\*.wav"^|jrepl "^((.+?) - .+?)(?:\[Disc (\d+)])?\.wav$" "$&|$1|$2|$3" /i'
) do if exist "%%~nA.jpg" if exist "%%~nA.cue" (
%= disc and count are both 1 if %%D is empty =%
if "%%D" equ "" (
flac.exe -0 --picture="%source%\%%~nA.jpg" --tag-from-file="CUESHEET=%source%\%%~nA.cue" -T "ALBUMARTIST=%%C" -T "DISCNUMBER=1" -T "TOTALDISCS=1" "%source%\%%A"
%= else count the number of .wav files =%
) else for /f %%E in ('dir /b /a-d "%%B[*.wav"^|find /c /v ""') do (
flac.exe -0 --picture="%source%\%%~nA.jpg" --tag-from-file="CUESHEET=%source%\%%~nA.cue" -T "ALBUMARTIST=%%C" -T "DISCNUMBER=%%D" -T "TOTALDISCS=%%E" "%source%\%%A"
)
)
popd
Again, you can add an IF to the outer loop to proceed only if the .flac file does not already exist in the destination.

Batch For Variables Printing Registry CSV

When querying the below via cmd
REG QUERY "HKCU\Printers\Connections"
The output is:
HKEY_CURRENT_USER\Printers\Connections\,,xxx-SD-KDP11,Colour
HKEY_CURRENT_USER\Printers\Connections\,,xxx-SD-KDP11,Mono
However when running the Batch file containing code below
#echo OFF
setlocal enableextensions enabledelayedexpansion
echo ============================
echo Network Printers ...
if exist network_printers.txt del network_printers.txt
if exist network_printers2.txt del network_printers2.txt
set reg_keys=
set blank=
set printers_network_paths=
set printers_network_types=
REG QUERY "HKCU\Printers\Connections" > network_printers.txt
for /f "tokens=* delims=" %%A in ('type network_printers.txt') do set network_printers_init=!network_printers_init! %%A
echo !network_printers_init! > network_printers2.txt
echo !network_printers_init!
pause
for /f "usebackq tokens=1,* delims=, skip=4" %%a in ('network_printers2.txt') do (
set reg_keys = !reg_keys! %%a
)
for /f "tokens=2,* delims=, skip=4" %%a in ('type network_printers2.txt') do (
set blank = !blank! %%b
)
for /f "tokens=3,* delims=, skip=4" %%a in ('type network_printers2.txt') do (
set printers_network_names = !printers_network_names! %%c
)
for /f "tokens=4,* delims=, skip=4" %%a in ('type network_printers2.txt') do (
set printers_network_types = !printers_network_types! %%d
)
echo reg_keys: !reg_keys!
echo blank: !blank!
echo Network Printers paths: !printers_network_names!
echo Network Printers types: !printers_network_types!
echo Network Printers paths: !printers_network_names! >> %file%
echo Network Printers types: !printers_network_types! >> %file%
pause
the .csv file produced has nothing for !printers_network_names! and !printers_network_types!
Also the echo lines show nothing being stored in the last 4 variables.
Please advise?
In a for /f loop, "skip=4" means skip 4 lines, but network_printers2.txt only contains one line.
There's some other stuff that can be improved. Mainly, when you set a variable in batch scripting, you should set "varname=string", quoted like that and with no spaces surrounding the =. You can also do what you need without the intermediate text files and the useless use of type.
I'm not entirely certain what you want the end result to be, but it looks like you're making your script a whole lot more complicated than it needs to be.
#echo OFF
setlocal enableextensions enabledelayedexpansion
echo ============================
echo Network Printers ...
for /f "tokens=2* delims=," %%A in ('REG QUERY "HKCU\Printers\Connections"') do (
set "printers_network_names=!printers_network_names! %%A"
set "printers_network_types=!printers_network_types! %%B"
)
echo Network printer paths: !printers_network_names!
echo Network printer types: !printers_network_types!
Result:
============================
Network Printers ...
Network printer paths: xxx-SD-KDP11 xxx-SD-KDP11
Network printer types: Colour Mono

Batch failure set value to a variable

this is my code:
#echo off
Setlocal EnableDelayedExpansion
set log=C:\mylog.log
set ftpFolder=C:\contributor\ftp
set rotterdamFolder=C:\rotterdam
cd /D C:\contributor
echo [FTP Folder: %ftpFolder%] >> %log%
cd /D %ftpFolder%
for /D %%f in (*) do (
cd %%f
for %%i in (*) do (
echo [FTP, %%f] Sending %%i >> %log%
for /f "tokens=1,2" %%a in (C:\input.txt) do (
if %%a==%%f (
set et=%%b
)
)
copy %ftpFolder%\%%f\%%i %rotterdamFolder%\%et% >> %log%
)
cd .. >> %log%
)
input.txt file is something like:
007 87855
008 87823
015 87830
it's not important how the two columns are divided (tab or space).
my problem is that %et% variable is not defined. how is it possible? I need to use variable "b" as destination folder. where is the error?
%et% is expanded when the line is parsed, and the entire outer parenthesized FOR loop is parsed all at once. So the value you get is the value that existed before your loop was entered.
You could solve the problem by enabling delayed expansion and using !et! instead. Type HELP FOR or FOR /? from the command line for more information. The section about delayed expansion is about halfway down.
But there really isn't any need to use the et variable at all. I believe you only want to copy the file when the first column of the inner loop matches the folder name. Simply move and substitute the COPY command for the SET statement. Use %%b instead of %et% in the COPY statement.
It wasn't necessary, but I substituted PUSHD/POPD for the CD commands. The redirection with CD is pointless when a path is specified.
You really should quote your paths in case they contain spaces or special characters.
for /D %%f in (*) do (
pushd "%%f"
for %%i in (*) do (
echo [FTP, %%f] Sending %%i >> %log%
for /f "tokens=1,2" %%a in (C:\input.txt) do if "%%a"=="%%f" (
copy "%ftpFolder%\%%f\%%i" "%rotterdamFolder%\%%b" >> %log%
)
)
popd
)