2014년 8월 27일 수요일

Perl 사용하지 않는 png 이미지 찾기

사용하지 않는 png 이미지 찾아 result.txt 로 출력하는 perl.


#!/usr/bin/perl

# SearchToNotUsePng.pl
# seesky89 20140826
# usage :
#    Android Application 개발시 사용하지 않는 png 이미지 제거를 위해 만듬.
#    cgywin(for Windows) 또는 리눅스에서 아래 명령 입력(상위 폴더기준)
#    perl SearchToNotUsePng.pl
#    정확성을 위해 gen, bin 폴더는 삭제 필요.

use strict;
use warnings;
use File::Find;
use File::Find qw(find);
use Cwd;


my $dir = '.';

open FH, ">", "result.txt" or die "$!\n";

my $mainDir = getcwd;
print FH "Search to not use resource. you need to check.\n";
print FH $mainDir, "\n";
print FH "------------------------------------------------------------\n";

find(\&find_use_file, $dir);

close FH;

print ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n";
print "Check to result.txt\n";
print ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n";

sub find_use_file {

    my $file = $_;
    my $currentDir = getcwd;
    
    if (-d $file) {
        #print "skip dir : $file\n";
    } elsif (-f $file) {
        #print "file : $file\n";

        if (/\b.9.png\b/i) {
            print "search file : $File::Find::name\n";

            # filename.png
            my $lastindex = rindex($file, '.9');
            my $search = substr($file, 0, $lastindex);

            $currentDir = getcwd;
            chdir('../..');

            my $ret = system("find . -name -prune -o -type f \( -name '*.java' -o -name '*.xml' -o -name '*.c' \) -print0 | xargs -0 grep --color -n $search");
            if($ret != 0) {
                print FH $File::Find::name, "\n";
            }

            chdir($currentDir);

        } elsif (/\b.png\b/i) {
            print "search file : $File::Find::name\n";
            
            # filename.png
            my $lastindex = rindex($file, '.');
            my $search = substr($file, 0, $lastindex);


            $currentDir = getcwd;
            chdir('../..');

            my $ret = system("find . -name -prune -o -type f \( -name '*.java' -o -name '*.xml' -o -name '*.c' \) -print0 | xargs -0 grep --color -n $search");
            if($ret != 0) {
                print FH $File::Find::name, "\n";
            }
            
            chdir($currentDir);
        } else {
            #print "skip other file : $file\n";
        }
    }
}

댓글 없음:

댓글 쓰기

Android Jetpack viewpager2

  Android Jetpack ViewPager2 기본 개념 및 샘플 코드 오늘은 안드로이드 개발에 있어서 굉장히 유용한 컴포넌트 중 하나인 ViewPager2에 대해 이야기해볼까 합니다. ViewPager2는 사용자 인터페이스에서 여러 화면을 좌우...