[ale] Cutting up directory

Joseph A. Knapka jknapka at earthlink.net
Thu Feb 8 17:27:19 EST 2001


> Chris Fowler wrote:
> 
> I have a directory that is 4GB is size, how can I cut it up into 700MB
> chunks for burning to CD.  It is too hard to do it manually and I have
> many files to backup.
> 
> Thanks,
> Chris
 
Here's a Tcl script that does what you want. Save it as
"dirsplit.tcl" and then run "tclsh dirsplit.tcl <directory> <size>"
It will produce output each line of which contains a space-separated
list of files totalling <size> K or less. It recurses on directories
and returns path names in the file lists exactly the way "find"
does. You can split the output at newlines and write input files
for tar, or whatever. Probably someone else can tell you how to do
the same thing with bash.

set dir [lindex $argv 0]
set sizeK [lindex $argv 1]

set allFiles [exec find $dir -type f -print]

set size 0
set fileList ""
set maxSize [expr $sizeK * 1024]
foreach filename $allFiles {
    set fsize [file size $filename]
    if {[expr $size + $fsize] > $maxSize} {
	puts $fileList
	set size $fsize
	set fileList "$filename"
    } else {
	incr size $fsize
	set fileList [concat $fileList " "]
	set fileList [concat $fileList $filename]
    }
}
puts $fileList

-- Joe Knapka
--
To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.





More information about the Ale mailing list