Today's Issues is:

OK I have a directory full of files. They should all be *.jpg's and be in number format. Here is what I need to do.

Look at file name. If file name is not 6 digits (exp: 123456.jpg) add 0 to the front until it is (exp: so 1234.jpg becomes 001234.jpg). Then I need to get those first 3 digits. OK then I need to create a directory by those first 3 digits if it does not already exist. Then move the file with it's new name to that directory. It needs to do this with every file in this directory (approx 42,000 images).

OK I guess what I need help with is trying to figure out the regex junk (never been my strong point). I read in the directory how do I do the the match to see if the file is 3 or 4 or 5 or 6 digits long and how would I add the characters to the front of the files and get those first 3 digits??


-----------------------
Billy S.
Slinar Hardtail - Hand of Dane
Datal Ephialtes - Guildless
RallosZek.Net Admin/WebMaster

perl -e '$cat = "cat"; if ($cat =~ /\143\x61\x74/) { print "Its a cat! +\n"; } else { print "Thats a dog\n"; } print "\n";'

In reply to File Name Pattern by LostS

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.