3

我已经有一个批处理文件,它显示按文件类型排序的文件夹中的文件列表:

dir /b /o:gen>filelisting.txt

我想制作一个 .bat 文件,该文件还将显示图像的宽度和高度。有没有人有代码可以做到这一点,或者比我更了解这种类型的编程?

4

2 回答 2

2

这是一个tooltipInfo.bat(jscript\bat 混合,可用作 a .bat),它获取文件的 toptip 信息,不需要任何外部软件:

@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();

如果对图片使用,则输出:

C:\TEST.PNG :
Item type: PNG image
Dimensions: ?871 x 836?
Size: 63.8 KB

这样你就可以:

for %%# in (*.jpg *.png *.tiff *.gif *.bmp) do (
    echo %%#
    for /f "delims=? tokens=2" %%a in ('toolTipInfo.bat "%%~#" ^|find "Dimensions:"')  do echo %%a
)

使用imgInfo.bat

于 2015-01-26T13:47:31.460 回答
1

尝试将其保存为 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

然后从命令行:

cscript c:\xxx.vbs "C:\whatever\My Pictures"

对我来说,产生;

a926_thumb 180  180
abstract1 2197  1374
backscreen 1024  1024
burgin_small 207  205

其中第一个数字是宽度和第二个高度。

于 2011-06-29T15:08:17.647 回答