Reputation: 75
I already have a batch file that displays the list of files in the folder ordered by file type:
dir /b /o:gen>filelisting.txt
I would like to make a .bat file that will also display the width and height of the images. does anyone have code that will do that or understands this type of programming better than i can?
Upvotes: 3
Views: 5243
Reputation: 57272
Here's a tooltipInfo.bat (jscript\bat hybrid that can be used as a .bat
) that takes the tooptip information for a file and does not require any external software:
@if (@X)==(@Y) @end /* JScript comment
@echo off
rem :: the first argument is the script name as it will be used for proper help message
cscript //E:JScript //nologo "%~f0" %*
exit /b %errorlevel%
@if (@X)==(@Y) @end JScript comment */
//////
FSOObj = new ActiveXObject("Scripting.FileSystemObject");
var ARGS = WScript.Arguments;
if (ARGS.Length < 1 ) {
WScript.Echo("No file passed");
WScript.Quit(1);
}
var filename=ARGS.Item(0);
var objShell=new ActiveXObject("Shell.Application");
/////
//fso
ExistsItem = function (path) {
return FSOObj.FolderExists(path)||FSOObj.FileExists(path);
}
getFullPath = function (path) {
return FSOObj.GetAbsolutePathName(path);
}
//
//paths
getParent = function(path){
var splitted=path.split("\\");
var result="";
for (var s=0;s<splitted.length-1;s++){
if (s==0) {
result=splitted[s];
} else {
result=result+"\\"+splitted[s];
}
}
return result;
}
getName = function(path){
var splitted=path.split("\\");
return splitted[splitted.length-1];
}
//
function main(){
if (!ExistsItem(filename)) {
WScript.Echo(filename + " does not exist");
WScript.Quit(2);
}
var fullFilename=getFullPath(filename);
var namespace=getParent(fullFilename);
var name=getName(fullFilename);
var objFolder=objShell.NameSpace(namespace);
var objItem=objFolder.ParseName(name);
//https://msdn.microsoft.com/en-us/library/windows/desktop/bb787870(v=vs.85).aspx
WScript.Echo(fullFilename + " : ");
WScript.Echo(objFolder.GetDetailsOf(objItem,-1));
}
main();
Output if used against a picture:
C:\TEST.PNG :
Item type: PNG image
Dimensions: ?871 x 836?
Size: 63.8 KB
so you can:
for %%# in (*.jpg *.png *.tiff *.gif *.bmp) do (
echo %%#
for /f "delims=? tokens=2" %%a in ('toolTipInfo.bat "%%~#" ^|find "Dimensions:"') do echo %%a
)
OR with imgInfo.bat
Upvotes: 1
Reputation: 175876
Try saving this as xxx.bat;
Dim oDir: Set oDir = CreateObject("Shell.Application").Namespace(Wscript.Arguments.Item(0))
For Each oFile In oDir.Items
wscript.echo oFile & " " & replace(oDir.GetDetailsOf(oFile,26), "x", "")
Next
Then from the command line:
cscript c:\xxx.vbs "C:\whatever\My Pictures"
For me, produces;
a926_thumb 180 180
abstract1 2197 1374
backscreen 1024 1024
burgin_small 207 205
Where the 1st number is width & the 2nd height.
Upvotes: 0