Page 1 of 1 1
Topic Options
#135129 - 2005-03-09 09:17 AM Math not working as expected
HeartCore Offline
Fresh Scripter

Registered: 2005-03-01
Posts: 17
Something else came up

Code:

$e = "%userprofile%\Mijn documenten"
$mydocs = dirplus($e, "/s")
for each $file in $mydocs
$docfiles=$docfiles+$file.size
next
? $docfiles + " used by My Documents



Now then, the code seems to work because I'm getting some numbers but they are wrong. When I do a dir /s in my documents, I get 147.411.122 bytes in 133 files. However, when I run the script I get 178.325.888 bytes (the loop runs 87 times which makes sense because when I subtract the number of folders that reside under my documents, I end up with that number).

Anyone has a clue why kix counts 170+ MB data and Windows only 140?

What I want to do with this script is to get an idea how much space is in use by our users profiles on the local harddisk so we can plan migrating this data to a fileserver.

Henk

Top
#135130 - 2005-03-09 10:17 AM Re: Math not working as expected
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Two possible reasons spring to mind.
1) The KiXtart script includes the sizes of the directories as well as the files in them.
2) The KiXtart script counts the blocks used and not just the file length. This would include the wasted space in the final file block.

You should be able to determine the reason yourself by picking a small directory to test and adding some verbose output.

Top
#135131 - 2005-03-09 10:42 AM Re: Math not working as expected
HeartCore Offline
Fresh Scripter

Registered: 2005-03-01
Posts: 17
Acutally both thing you mention seemd to apply:

Code:

$e = "%userprofile%\Mijn documenten"
$mydocs = dirplus($e, "/s")
for each $file in $mydocs
if NOT GetFileAttr($file) = 16 ; not a directory
$docfiles=$docfiles+GetFileSize($file)
endif
next
? $docfiles + " used by My Documents



Reports the correct size now.

Thanks
Henk

Top
#135132 - 2005-03-09 03:03 PM Re: Math not working as expected
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
If you just want the files, use the dirplu() /a-d option, it will only return the files.

Code:

$e = "%userprofile%\Mijn documenten"
$mydocs = dirplus($e, "/s /a-d")
for each $file in $mydocs
$docfiles=$docfiles+GetFileSize($file)
next
? $docfiles + " used by My Documents



Top
#135133 - 2005-03-09 04:35 PM Re: Math not working as expected
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Although if you are using it for sizing, you probably want to include the directory sizes as these will consume disk at the new location too.
Top
#135134 - 2005-03-09 04:45 PM Re: Math not working as expected
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
if all you want is the folder size....


$folder = "c:\temp"
$foldersize = CreateObject("Scripting.FileSystemObject").GetFolder($folder).size


Top
#135135 - 2005-03-09 05:00 PM Re: Math not working as expected
HeartCore Offline
Fresh Scripter

Registered: 2005-03-01
Posts: 17
Quote:

Although if you are using it for sizing, you probably want to include the directory sizes as these will consume disk at the new location too.




I'm not sure what's happening.... For example, there's 47 directories in my own 'my documents' folder. If I include the size of the dirs in my script, it tells me these 47 directories are about 30 megs together and that doesn't seem right to me.


Top
#135136 - 2005-03-09 05:15 PM Re: Math not working as expected
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Odd. Maybe you're picking up a special file or link.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 847 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.055 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org