I wanted to play:
#!/usr/bin/perl use warnings; use strict; use Path::Tiny; use File::Find; sub random_char { my @allowed = @_; return $allowed[ rand @allowed ] } sub random_name { my ($length, @allowed) = @_; return join q(), map random_char(@allowed), 1 .. $length } sub create_dirs { my ($max_dirs, $max_length, $max_files, $depth, @characters) = @_; my %dirs; my $count_dirs = 1 + int rand $max_dirs; while (keys %dirs < $count_dirs) { my $dirname = random_name(1 + rand $max_length, @characters); redo if -f $dirname; undef $dirs{$dirname}; } for my $dir (keys %dirs) { path($dir)->mkpath; chdir $dir; my $count_files = 1 + int rand $max_files; my %files; undef $files{ random_name(1 + rand $max_length, @characters) } while keys %files < $count_files; path($_)->touch for keys %files; if (int rand $depth) { create_dirs($max_dirs, $max_length, $max_files, $depth - 1, @characters); } chdir '..'; } } sub check { my ($max_files, $max_dirs, $max_depth) = @_; sub { return unless -d $File::Find::name; my @dirs = glob $File::Find::name . '/*/'; s=/$== for @dirs; my %files; undef @files{ glob $File::Find::name . '/*' }; delete @files{ @dirs }; my $count_files = keys %files; my $count_dirs = @dirs; my $depth = $File::Find::name =~ tr=/==; die "Too many files in $File::Find::name: $count_files" if $count_files > $max_files; die "Too many dirs in $File::Find::name: $count_dirs" if $count_dirs > $max_dirs; die "Directory too deep: $File::Find::name " if $depth > $max_ +depth; } } sub main { my $max_depth = 5; my $max_dirs = 4; my $max_files = 5; my $max_length = 4; my @characters = ('A' .. 'Z', '0' .. '9', '_'); create_dirs($max_dirs, $max_length, $max_files, $max_depth, @chara +cters); find(check($max_files, $max_dirs, $max_depth), '.'); } main();

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

In reply to Re: how create random directories and files hierarchy by choroba
in thread how create random directories and files hierarchy by gabrielsousa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.