使用pngcrush的Perl脚本,用于1级文件夹层次结构

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用pngcrush的Perl脚本,用于1级文件夹层次结构相关的知识,希望对你有一定的参考价值。

Wrote this script to work with pngcrush command line based program on Windows system to compress several .png images in multiple folders (with only 1 level of folders, rather than that you have to repeat doing it manually).

It's fast, and help doing the task at hand but it's completely clean.

Please note that the code doesn't take care for all un-expected result, it just does the job in controlled environment.

This script relates to my optimization on application's file size, check it out at the URL above.
  1. #!E:/strawberry/perl/bin/perl
  2. # Handy script for using pngcrush to compress the size of png files in multiple folders
  3.  
  4. $dir = "C:/Users/Haxpor/Desktop/in";
  5. $out = "C:/Users/Haxpor/Desktop/out/";
  6.  
  7. opendir(DIR, $dir) || die("Cannot open directory");
  8. @folders = readdir(DIR);
  9. closedir(DIR);
  10.  
  11. foreach $folder (@folders)
  12. {
  13. # read in each folder
  14. opendir(SUBFOLDER, $dir."/".$folder) || print("Error reading $folder ");
  15. @files = readdir(SUBFOLDER);
  16. closedir(SUBFOLDER);
  17.  
  18. # create dir in output folder
  19. mkdir($out."/".$folder);
  20.  
  21. # process each file
  22. foreach $file (@files)
  23. {
  24. if(-f $dir."/".$folder."/".$file && $file =~ /.*.png/i)
  25. {
  26. system("pngcrush $dir/$folder/$file $out/$folder/$file");
  27. }
  28. }
  29.  
  30. print " ";
  31. }

以上是关于使用pngcrush的Perl脚本,用于1级文件夹层次结构的主要内容,如果未能解决你的问题,请参考以下文章

shell脚本

Perl DBI - 使用多个语句运行 SQL 脚本

在 Perl 脚本中运行 PL/SQL 过程

为啥 ncat -exec 可以与 shell 脚本一起使用,但不能与 perl 脚本一起使用?

用 java 重写 Perl 和 shell 脚本有意义吗?

数字IC设计脚本编程系列——Perl基本概念