Hellow zarath,

Something like this should do what you want.

#!/usr/bin/perl use strict; use warnings; use File::Copy; use Data::Dumper; use File::Path qw(make_path); my $dir = shift || "."; opendir(my $dh, $dir) or die "cannot open directory $dir $!"; my @files = grep { /\.txt$/ && -f "$dir/$_" } readdir($dh); closedir $dh; # 0 1 2 3 4 5 6 7 8 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(t +ime); # $mon the month in the range 0..11 , with 0 indicating January and 11 $mon += 1; # $year contains the number of years since 1900. To get a 4-digit year + write: $year += 1900; # To get a 2-digit year write: my $short_year = substr $year, 2; my $new_dir = "$dir/$year/$mon/$mday"; eval { make_path($new_dir); 1 } or die "Can't create home directory: $@\n"; if (@files) { foreach my $file (@files) { # the perl file move function move("$dir/$file", $new_dir) or die "The move operation failed: $!"; } print Dumper \@files; } else { print "No files found to move\n"; } __DATA__ $ perl test.pl $VAR1 = [ 'counts.txt', 'file.txt', 'test.txt' ]; ~/Monks$ ll 2017/5/23/ total 16 drwxrwxr-x 2 tinyos tinyos 4096 May 23 13:29 ./ drwxrwxr-x 3 tinyos tinyos 4096 May 23 13:23 ../ -rw-rw-r-- 1 tinyos tinyos 0 May 9 15:19 counts.txt -rw-rw-r-- 1 tinyos tinyos 24 May 9 11:53 file.txt -rw-rw-r-- 1 tinyos tinyos 465 May 9 15:55 test.txt $ perl test.pl No files found to move

If you want you can set permissions, read (File::Path). I also used (readdir and File::Copy).

There are multiple ways of resolving your task, this is just one.

Update:

Adding if and else condition on greped files.

Hope this helps.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Wildcards for a wide array of strings? by thanos1983
in thread Wildcards for a wide array of strings? by zarath

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.