Getting [free disk space] in tcl 
Author Message
 Getting [free disk space] in tcl

    I'm trying to write a program that, among
other things, copies files to floppy disks. I
want to make sure that the disk has sufficient
free space for the file to be copied. How can I
know the amount of free space on disk and put it
on a tcl variable?

--== Sent via Deja.com http://www.*-*-*.com/
---Share what you know. Learn what you don't.---



Sun, 11 Nov 2001 03:00:00 GMT  
 Getting [free disk space] in tcl

Quote:

>     I'm trying to write a program that, among
> other things, copies files to floppy disks. I
> want to make sure that the disk has sufficient
> free space for the file to be copied. How can I
> know the amount of free space on disk and put it
> on a tcl variable?


Is Usenet great or what?!! :-) Check out the thread entitled "df on Tcl" to
see the solution proposed by Cameron Laird. Of course, if you're working on an
infer... a non-Unix platform (as I suspect), you won't be helped at all be
Cameron's code.

L

--
Penguin Power!           Nothing I say reflects the views of my employer


CGI - FWFM Project                                 Phone: (514) 391-9523



Sun, 11 Nov 2001 03:00:00 GMT  
 Getting [free disk space] in tcl

Quote:


> >     I'm trying to write a program that, among
> > other things, copies files to floppy disks. I
> > want to make sure that the disk has sufficient
> > free space for the file to be copied. How can I
> > know the amount of free space on disk and put it
> > on a tcl variable?

> Is Usenet great or what?!! :-) Check out the thread entitled "df on Tcl" to
> see the solution proposed by Cameron Laird. Of course, if you're working on an
> infer... a non-Unix platform (as I suspect), you won't be helped at all be
> Cameron's code.

Try this worm:
regsub -all {[.]} [lindex [lindex [split [exec cmd /c dir A:] \n] end]
0]  "" freebytes

Step by step:
exec cmd /c dir A: ;# or whatever drive you'd like to fathom
        starts a WinNT shell (on Win95, it's command for cmd, I think) with the
        specified command, which in the last line gives the number of free
bytes
lindex [split [exec cmd /c dir A:] \n] end
        turns the CR-separated lines into a list, returns the last line
lindex [lindex [split [exec cmd /c dir A:] \n] end] 0
        extract the number (1st list element)
regsub -all {[.]} [lindex [lindex [split [exec cmd /c dir A:] \n] end]
0]  "" freebytes
        removes the periods in the number (I have a German installation; on US
        Windows there may be commas instead) and puts the rest to variable
freebytes

Hope that helps :-)



Sun, 11 Nov 2001 03:00:00 GMT  
 Getting [free disk space] in tcl
Hey Cameron,

Does this help a bit?

Quote:

> Try this worm:
> regsub -all {[.]} [lindex [lindex [split [exec cmd /c dir A:] \n] end]
> 0]  "" freebytes

> Step by step:
> exec cmd /c dir A: ;# or whatever drive you'd like to fathom
>    starts a WinNT shell (on Win95, it's command for cmd, I think) with the
>    specified command, which in the last line gives the number of free
> bytes
> lindex [split [exec cmd /c dir A:] \n] end
>    turns the CR-separated lines into a list, returns the last line
> lindex [lindex [split [exec cmd /c dir A:] \n] end] 0
>    extract the number (1st list element)
> regsub -all {[.]} [lindex [lindex [split [exec cmd /c dir A:] \n] end]
> 0]  "" freebytes
>    removes the periods in the number (I have a German installation; on US
>    Windows there may be commas instead) and puts the rest to variable
> freebytes

If you do

exec cmd /c dir /-c A:

or whatever, the periods are removed for you, which is one munging step less.
The /-c option to dir removes thousand-delimiters, which is then portable
across versions, I guess. But I don't know if the above will work in any East
Asian countries.

L

--
Penguin Power!

Laurent Duperval
CGI - FWFM Project
Phone: (514) 391-9523



Sun, 11 Nov 2001 03:00:00 GMT  
 Getting [free disk space] in tcl

Quote:

>     I'm trying to write a program that, among
> other things, copies files to floppy disks. I
> want to make sure that the disk has sufficient
> free space for the file to be copied.

<pendantic>

You can't. All the operating systems that Tcl runs on are multitasking.
There's no way to find out if the free space you tested for is still
going to be there by the time you finished writing the file.  Since you
ought handle this problem anyway, you should not need to know how much
space is on the disk.

This is, of course, more important in serious software.

</pendantic>

<windows>

And apparently, there's a system-call to preallocate a
hopefully-contiguous chunk of space for a file then copy into it, which
is what the file explorer does when you drag files around. If you wind
up writing windows-specific C code, you might as well use this.

</windows>

--
Darren New / Senior Software Architect / MessageMedia, Inc.
     San Diego, CA, USA (PST).  Cryptokeys on demand.
Help outlaw Dihydrogen monoxide, a major component of acid rain!



Sun, 11 Nov 2001 03:00:00 GMT  
 Getting [free disk space] in tcl

Quote:

> If you do

> exec cmd /c dir /-c A:

> or whatever, the periods are removed for you, which is one munging step less.
> The /-c option to dir removes thousand-delimiters, which is then portable
> across versions, I guess. But I don't know if the above will work in any East
> Asian countries.

Thank you, Laurent - I should have RTFM...
But one add-on: I tried this with "command" instead of "cmd" on my 95
box last night, and
it brought my wish to a standstill - had to kill it from the task
manager. The launched command.com had to be killed at shutdown. So, this
solution seems to work on NT only.

Best regards, Richard Suchenwirth



Mon, 12 Nov 2001 03:00:00 GMT  
 Getting [free disk space] in tcl

Quote:

> Thank you, Laurent - I should have RTFM...
> But one add-on: I tried this with "command" instead of "cmd" on my 95
> box last night, and
> it brought my wish to a standstill - had to kill it from the task
> manager. The launched command.com had to be killed at shutdown. So, this
> solution seems to work on NT only.

Well, 95/98 aren't really OS's, are they?

--
Penguin Power!           Nothing I say reflects the views of my employer


CGI - FWFM Project                                 Phone: (514) 391-9523



Mon, 12 Nov 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. getting [free disk space]

2. Free disk space in Carbon/OS X apps?

3. Free space on disk

4. disk free space

5. Free Disk Space (on NT)

6. CFD 3101 - How to know free disk space?

7. free disk space

8. How to find free disk space on drive

9. Total and free Disk Space in 16 bit?

10. Free Disk Space

11. Free Disk Space

12. Disk Free Space (help!)

 

 
Powered by phpBB® Forum Software