创建一个Perl脚本来批量处理文件 [英] Creating a perl script to batch process files

查看:363
本文介绍了创建一个Perl脚本来批量处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这行代码:

convert 1234_Page_1_....png 1234_Page_2_....png output.pdf 

这会将那些特定的png合并为一个pdf(使用ImageMagick).我有一堆这种格式的文件.我想对" Page "之前具有相同编号的文件执行此合并/转换为pdf的操作.有时有两个以上的页面要转换.

This merges those particular pngs to a single pdf (using ImageMagick). I have a bunch of files in this format. I would like to perform this merging/converting-to-pdf action on files that have the same number before the "Page". Sometimes there are more than two pages to convert.

我想在可以在Windows上运行的perl脚本中完成此操作.

I would like to have this done in a perl script that I can run on Windows.

预先感谢, 杰克

推荐答案

如果您想根据需要多次调用convert(1):

If you wanted to call convert(1) as few times as necessary:

#! /usr/bin/perl

use strict;
use warnings;

my %processed = ();
for my $prefix (map { /^(\d+)/ } glob('[1-9]*_Page_*.png')) {
    next if $processed{$prefix}++;
    system("convert ${prefix}_Page_*.png ${prefix}_output.pdf");
}

这篇关于创建一个Perl脚本来批量处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆