Go Back   FlashFXP Forums > >

Programming Need help with C/C++/Delphi? Ask here and make us all laugh.

Closed Thread
 
Thread Tools Rate Thread Display Modes
Old 05-27-2005, 04:40 AM   #1
djdeluxe76
Member
 
Join Date: Mar 2005
Posts: 43
Default How to get Size of a dir in TCL ?

Hello, and (yet another) 'thank you' for reading this...

I have been looking this up everywhere (to my knowledge that is) but
I cannot find it in the ActiveTcl Manual. I stumbled upon a module called
TWAPI (Tcl Windows API) hoping that this would give me hooks to
explorer attributes.... but no, only for files and then only for access
rights...

It can't be that getting the size of a directory is not a common task no
matter which language you are using.

So how do I fetch this in Tcl, please?

Thanks for any and replies or pointers to additional text.

Cheers
DJ
djdeluxe76 is offline  
Old 05-27-2005, 05:05 AM   #2
djdeluxe76
Member
 
Join Date: Mar 2005
Posts: 43
Default

Just found this on tcl.tk

Quote:
Fred Limouzin: 2005/04/11

The file size command currently (i.e. Tcl8.4.9) does not support
directories. A pure-Tcl solution involves adding recursively the size of
files in the current and in sub-directories.

Here's a Tk/GUI script that I wrote this week-end, which fits my
need. I wanted a gradient-color indication for the size of directories.
You can position the orange/yellow scale (size at which the color
indicator is orange/yellow; below that value the indicator is gradient
going toward green (size=0)) and the red scale (size from which the
indicator is red!). A scale selector also lets you decide how many
levels of sub-directories to display. read more...
Get source code for directory size.

There is also a link on that page to source code from the UNIX du (disk usage) TCL implementation.

So, as I understand it, it's actually really not possible to get the size
all at once. You have to recursively read the size from all files??
Or maybe I don't fully understand yet what I have found above....

DJ
djdeluxe76 is offline  
Old 05-27-2005, 11:55 AM   #3
tuff
Senior Member
FlashFXP Registered User
ioFTPD Scripter
 
Join Date: Jan 2003
Posts: 277
Default

set srcpath [resolve pwd $pwd$release]
set nesting 3
set knownfiles 0
set knowndirs 0
set subdir "*"
set sizeneeded 0

for {set level 0} {$level < $nesting} {incr level} {
set test [glob -nocomplain -directory $srcpath "$subdir"]
foreach dir $test {
if {[file isdirectory "$dir"]} {
lappend dirs "$dir "
incr knowndirs
} else {
if {![string match -nocase "*/.*" $dir]} {
incr knownfiles
}
}
set sizeneeded [expr [expr $sizeneeded + [file size $dir]] * 1.0]
}
append subdir "/*"
}
set sizeneeded [expr [expr $sizeneeded / 1024] * 1.0]

this is basically what i use in ioPRE to check for enough free space
in a destination path before `pre`, i guess you can work out the rest
__________________
#iotools #ioftpd (both on efnet)
tuff is offline  
Old 05-28-2005, 12:24 PM   #4
djdeluxe76
Member
 
Join Date: Mar 2005
Posts: 43
Thumbs up

Hello tuff,

Let me thank you very much for sharing your knowledege

I am working with your code now as this is very much all I needed
already. Just have to look at it for some time until I fully understand it

Cheers
DJ
djdeluxe76 is offline  
Closed Thread

Tags
access, files, size, task, tcl

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 09:00 AM.

Parts of this site powered by vBulletin Mods & Addons from DragonByte Technologies Ltd. (Details)