[Gllug] Script for splitting dirs
itsbruce at uklinux.net
itsbruce at uklinux.net
Tue Jun 3 12:14:14 UTC 2003
On Tue, Jun 03, 2003 at 12:38:32PM +0100, Brent Geach wrote:
> I want the script to scan through a dir by date and then move all files to a
> datedir eg (0304-0404) until that dir gets to 1G in size then create new dir
> and fill that up till 1G etc etc etc.
>
> Any ideas?
Use Perl. This would be a complete pain to do as a shell script. With
Perl it's a simple matter of using readdir() to get an array of all the
files in the directory and stat() to get the size of each file. Then
you iterate through the array of files, checking the size of each before
copying.
A couple of tips:
1. A simple extra that would avoid some wastage would be this: once you
get to a file that would, if copied into the current target, take the
size over the limit, don't just go on to the next target. Instead,
start adding files to a second array that you will use for the next
target but look out for any that will still fit into the current target.
Only go on to the next target when either you have completely filled the
current target or there are no files left that would fit into the
remaining space. There are more intelligent algorithms you could use to
split the array of files with the maximum space saving but that will at
least avoid some waste, unless the files are all of similar sizes.
2. stat can give you both the size of the file and the actual space it
occupies on the disk.
--
Bruce
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list