[ale] Cutting up directory

Stephen Lastinger s.lastinger at computernetdesign.com
Tue Feb 13 08:04:49 EST 2001


This is why I love this group.  Very nice Joseph, I know that the text
install for the RH distro's was written in tcl (or at least at one time
it was), but until now had never seen tcl syntax.

It's also timely to see as I have been debating on a scripted/interpreted
language to learn (for fun - at least for now as I still have ANSI SQL
to get under the belt) and had only really considered python and perl.

(Truth be told, I have been leaning wards python.  Perl's '$_' for some
reason drives me crazy and I still have a prejudice to it thanks to a
distasteful, 2nd rate admin., former cow-orker and his ceaseless worship
at the alter of perl.....)

There was a nice brief overview and listing of choices on:
http://www.sunworld.com/unixinsideronline/swol-02-2001/swol-0202-regex.html

Not trying to start a flame war here, but would anyone care to comment on
the virtues of their favorite (yes, perl included ; ), or on why they
chose one over the other, or if proficient in more than one, which one
fits best into what role and why?

-Stephen


On Thu, 8 Feb 2001, Joseph A. Knapka wrote:
[snip..]

> 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