in reply to Random Files Recursively Form Directory
When you say user gives a max limit (in percentage), is that for all the files in the directory or only the target files in the directory? e.g. say you are supposed to just check 25% (size, not quantity) and 75% of the directory is made up of extensions you are not interested in, does that mean you will scan all of the files with extensions you are interested in?
I can give you one approach (assuming the max limit given by user is for % of files that match extension (not % of all files):
Use File::Find to find all files with extensions you are interested in.
With the help of "-s" or stat() to get the file sizes, build a data structure that looks like this:
For each random file in "filelist" (can use Shuffle in List::Util for this), scan/process file as long as sum of size of files processed in the directory does not exceed the user supplied percentage of dir_size.
Use File::Find to find all files with extensions you are interested in.
With the help of "-s" or stat() to get the file sizes, build a data structure that looks like this:
Iterate through each directory in this structure.$myFiles = { "dir1" => { filelist => [ { filename => "file1.txt", size => 123 }, { filename => "file2.doc", size => 456 }, +], dir_size => 579, }, ... };
For each random file in "filelist" (can use Shuffle in List::Util for this), scan/process file as long as sum of size of files processed in the directory does not exceed the user supplied percentage of dir_size.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Random Files Recursively Form Directory
by gautamparimoo (Beadle) on Apr 02, 2013 at 05:07 UTC | |
by CountOrlok (Friar) on Apr 02, 2013 at 13:01 UTC | |
by gautamparimoo (Beadle) on Apr 03, 2013 at 05:22 UTC |
In Section
Seekers of Perl Wisdom