I have a directory with file names like: 2, 5, 7.

I have a file in sorted order containing names that corresponds to each file name. The the first line in the file would be the name of 2, the second would be 5, and so on.

What I want to do is rename each file to the name it corresponds to in the file. Example:

  • 2 rename to testfile1
  • 5 rename to testfile2
  • 7 rename to testfile3
  • I'm unsure how to approach doing this. Do I want to to create an array of the file names, sort it numerically and then go about renaming them? How would I make sure that the file named '2' corresponds to right line in the file I have of names?


    In reply to rename files by pbaumgar

    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.