I've got an array of several hundred filenames (complete with paths etc).

I need to traverse a directory (+ subdirs) and weed out all files that are in the directory structure but not in the array of files to keep.

Another way of expressing this would be, how can I do a directory difference, between a directory structure and an array of files.

I've thought of playing around with file::find, building arrays of the files on the disc, and doing an array comparision with the array of files to keep to get an array that holds all files that are on the HD but not in the files to keep array.

Or is there a better way of doing this?

Additionally, I could save the list of extraneous files by saving the extranous files array to disc. I could then loop through this and move all these files to a "trash" directory. At a later date, I could iterate through the trash directory and optionally restore any files in the trash directory to their previous place in the directory tree.

Any ideas?

thanks for your help, wisdom and enlightenment, o Monks.

dmtelf


In reply to Hard disc pruner by dmtelf

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.