Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
aGerman
- Expert
- Posts: 4654
- Joined: 22 Jan 2010 18:01
- Location: Germany
#16
Post
by aGerman » 09 Oct 2017 01:36
tlm2408 wrote:I haven't worked out how to do that yet with the exiftool.
Basically
Code: Select all
>"list.txt" echo foo
exiftool ... >>"list.txt"
>>"list.txt" echo bar
tlm2408 wrote:Just out of curiosity with the other batch file you gave me, how would I specify another property?
Currently you would have to call the JScript part several times for each property. I'll update the script this evening to support several properties at once. Currently I'm at work though.
Steffen
-
tlm2408
- Posts: 31
- Joined: 01 Aug 2017 01:19
#17
Post
by tlm2408 » 09 Oct 2017 02:18
Thank you Steffen. No rush mate. You have already gone above and beyond what I expected and I truely appeciate the time you have put in to helping me.
Also I totally forgot about the > to add text and >> to append in the exiftool bat. Opps!
-
aGerman
- Expert
- Posts: 4654
- Joined: 22 Jan 2010 18:01
- Location: Germany
#18
Post
by aGerman » 09 Oct 2017 13:29
The WSH JScript doesn't support most of the Javascript array methods. So I had to implement the loops for comparisons by hand.
Code: Select all
@if (@a)==(@b) @end /*
:: Batch
@echo off &setlocal
set "file=list.txt"
set "property1=Bit rate"
set "property2=Length"
set "property3=Year"
>"%file%" type nul
>>"%file%" (
for /r "C:\Audio" %%g in (*.mp3 *.flac) do (
set "fname=%%~nxg"
set "fpath=%%~fg"
setlocal EnableDelayedExpansion
<nul set /p ={"Title": "!fname!", "Fullpath": "!fpath:\=/!"
endlocal
for /f "tokens=1-3 delims=?" %%h in ('cscript //nologo //e:jscript "%~fs0" "%%~fg" "%property1%" "%property2%" "%property3%"') do (
if "%%h" neq " " <nul set /p =, "bitrate": "%%h"
if "%%i" neq " " <nul set /p =, "length": "%%i"
if "%%j" neq " " <nul set /p =, "year": "%%j"
)
echo },
)
)
exit /b&::*/ try {
var objFSO = WScript.CreateObject('Scripting.FileSystemObject'),
objWShell = WScript.CreateObject('WScript.Shell'), objShell = WScript.CreateObject('Shell.Application');
objWShell.CurrentDirectory = objFSO.GetParentFolderName(WScript.ScriptFullName);
var strFullName = objFSO.GetAbsolutePathName(WScript.Arguments(0)),
objFolder = objShell.Namespace(objFSO.GetParentFolderName(strFullName)),
objFolderItem = objFolder.ParseName(objFSO.GetFileName(strFullName)),
strPropName = '', val, arrArgs = [], arrVal = [], cnt = 0, i = 0, n = 0, found = false;
for (i = 1; i < WScript.Arguments.Count(); ++i) {
arrArgs.push(WScript.Arguments(i).toLowerCase());
arrVal.push(' ');
}
while ((strPropName = objFolder.GetDetailsOf(null, n)) != '' && cnt < arrArgs.length) {
found = false;
for (i = 0; i < arrArgs.length && found == false; ++i) {
if (strPropName.toLowerCase() == arrArgs[i]) {
if ((val = objFolder.GetDetailsOf(objFolderItem, n)) != null && val != '') {
arrVal[i] = val;
}
found = true;
++cnt;
}
}
++n;
}
WScript.Echo(arrVal.join('?'));
}
catch(e) {
WScript.StdErr.WriteLine(e.message);
WScript.Quit(1);
}
I hope those are the right property names this time.
Steffen
-
tlm2408
- Posts: 31
- Joined: 01 Aug 2017 01:19
#19
Post
by tlm2408 » 09 Oct 2017 23:05
Thank you so much Steffen, that works great!!! Exactly what I was looking for.
I'm very greatfull for your time and effort.
Greg