• 为该目录以及子目录添加index.html


    add index.html to a directory recursively

    using Perl5

    使用的目录,是从Perl下载的perl5.18.2的文档
    Look Here

    #!/usr/bin/perl
    # filename : ban.pl
    #为指定目录以及其子目录,每个都添加一个index.html裱糊文件
    use IO::Dir;
    use IO::File;
    my $indent = 0;
    &add_index_html("$ARGV[0]");
    sub touch {
    #相当于一个touch命令
       my $fh = IO::File->new("index.html",'w');
       if ($fh) {
           print $fh "<h1>Back to <a href="#">RenLab</a></h1>";
           $fh->close;
       }
    }
    sub add_index_html {
        my $dir  = shift;
        my $d = IO::Dir->new("$dir");
        if (defined($d)) {
            chdir $dir;
            print STDERR "$dir
    ";
            &touch;
            while (defined($_ = $d->read)) {
                next if ($_ =~ /^..?$/);
                #跳过 . 和 .. 目录
                #不然,一直循环 . 目录
                if (-d "$_") {
                #如果是一个子目录
                    $indent++;
                    print STDERR "  " x $indent;
                    #每一层目录缩进2个空格
                    chmod 0755, "$_";
                    &add_index_html("$_");
                    #也可以使用 __SUB__ feature
                    #处理子目录
                    $indent--;
                }else{
                    next
                }
            }
            chdir("..");
        }
    }
    

    现在,你可以

    perl ban.pl perdoc5.18.2
    perldoc5.18.2
      App
        Prove
          State
            Result
      Archive
        Tar
      Attribute
      B
        Lint
      CGI
      Class
      Compress
        Raw
      Config
      CPAN
      CPANPLUS
        Backend
        Dist
          Build
        Internals
          Source
        Module
          Author
        Shell
          Default
            Plugins
      Data
      DBM_Filter
      Devel
      Digest
      Encode
        CN
        JP
        KR
        MIME
        Unicode
      Exporter
      ExtUtils
        CBuilder
          Platform
        Command
        Constant
        MakeMaker
      File
        Spec
      Filter
        Util
      functions
      Getopt
      Hash
        Util
      I18N
        LangTags
      IO
        Compress
        Socket
        Uncompress
      IPC
      List
        Util
      Locale
        Maketext
      Log
        Message
      Math
        BigInt
      Memoize
      MIME
      Module
        Build
          Platform
        Load
        Pluggable
      Net
      Object
      Package
      Params
      Parse
        CPAN
      PerlIO
        via
      Pod
        Perldoc
        Simple
        Text
      Scalar
      Search
      static
      Sys
      TAP
        Formatter
          Console
          File
        Parser
          Iterator
          Result
          Scheduler
          YAMLish
      Term
        UI
      Test
        Builder
          Tester
      Text
      Thread
      threads
      Tie
        Hash
      Time
      Unicode
      User
      warnings
    天和地是灰色的,砖和瓦也是灰色的。临街的墙几经风化,几经修补,刷过黑灰、白灰,涂过红漆,书写过不同内容的标语,又终于被覆盖;风雨再把覆盖层胡乱地揭下来,形成一片斑驳的杂色,融汇于灰色的笼罩之中。路旁的树木苍黑,瓦楞中芳草青青。 远处,炊烟缭绕。迷蒙的曙色中,矗立着...
  • 相关阅读:
    select下拉框运用
    oracleINS-13001 环境不满足最低要求
    组成原理-存储器
    操作系统-- 存储器
    组成原理-CPU
    计算机网络-tcp-ip
    操作系统-处理机
    数据链路层~计算机网络
    物理层--计算机网络
    JavaScript-轮播2
  • 原文地址:https://www.cnblogs.com/raybiolee/p/5634549.html
Copyright © 2020-2023  润新知