需要一个批处理文件来列出具有尺寸的图像文件

发布于 2024-11-17 20:52:27 字数 170 浏览 3 评论 0原文

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

dir /b /o:gen>filelisting.txt

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何以心动 2024-11-24 20:52:27

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

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

OR
imgInfo.bat

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

初与友歌 2024-11-24 20:52:27

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文