Page 1 of 2 12>
Topic Options
#22675 - 2002-06-06 02:15 AM Dir () did not work well for me !!
Anonymous
Unregistered


Hi ,
I am using Dir () to calculate the number of files in a folder and some subdirectories under that tree .

code:
 
$Count = 0
$Filename = Dir( "C:\BigTree\*.*")
While $Filename <> "" and @ERROR = 0
$Count = $Count + 1
? $Filename
$Filename = Dir()
Loop
? $Count ; print the total files

_________________________________
The result just gave me all files at C:\BigTree folder, but not subdirectories's files under BigTree .


Any help would be appreciated
Don [Confused]

Top
#22676 - 2002-06-06 02:18 AM Re: Dir () did not work well for me !!
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Hi Donald, thats by design [Frown]
Top
#22677 - 2002-06-06 02:26 AM Re: Dir () did not work well for me !!
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Someone wrote a UDF that does a recursive Dir(). I'm sure if you searched the UDF Section you'd find it.

Then again, there's always the low-tech way to do it. Do a DOS DIR /S and redirect the results to a file. the last two lines will contain the numbers.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#22678 - 2002-06-06 02:37 AM Re: Dir () did not work well for me !!
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
OK... DOC shamed me into KiXing this up a notch. The recursive Dir() UDF is:

Topic: DirPlus() - a recursive dir tool

It's not a canned solution, but if you're up to the challenge, in the grande programming tradition, you could "borrow" from it.

(or maybe DOC will one-up me and actually can it for you) [Wink]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#22679 - 2002-06-06 02:38 AM Re: Dir () did not work well for me !!
Anonymous
Unregistered


No, actually I am doing more than just calculate the number of files. Low tech won't help me on this.
By the way, the main thing that I 'm finding the directory file size? Any ideas ?
Thanks
Don

Top
#22680 - 2002-06-06 02:51 AM Re: Dir () did not work well for me !!
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... low-tech gives you the totals in bytes as well.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#22681 - 2002-06-06 03:02 AM Re: Dir () did not work well for me !!
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Donald,

How about this quicky little recursive function ?

break on

$start = @TICKS

?"size=" getdirsize("c:\windows\system32")

?"elapsed=" @TICKS - $start "ms"

exit 1

function getdirsize($path)
 dim $filename
 $filename = dir("$path\*.*")
 while @error = 0
  if $filename <> "." and $filename <> ".."
   if getfileattr("$path\$filename") & 16
    $getdirsize = $getdirsize + getdirsize("$path\$filename")
   else
    $getdirsize = $getdirsize + getfilesize("$path\$filename")
   endif
  endif
  $filename=dir("")
 loop
endfunction



Not tested very much, but food for thought.

-Shawn

[ 06 June 2002, 18:37: Message edited by: Shawn ]

Top
#22682 - 2002-06-06 03:19 AM Re: Dir () did not work well for me !!
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Yeah, I know... I read the disclaimer YMMV

Gawd! it took forever to run compared to the DOS DIR. I should'a timed it.

The results of DIR WINNT:

Your UDF
size=1088981890

DOS DIR
Total Files Listed:
7867 File(s) 1,109,700,227 bytes

A minor discrepancy beween the results.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#22683 - 2002-06-06 03:24 AM Re: Dir () did not work well for me !!
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
But now Donald can shell-out to DOS, comfortable
in the knowledge that "the other way" really,
really sucks [Wink]

p.s. Les, thanks for NOT timing it [Wink]

ps.ps - how about the FileSystemObject - any methods there for grabbing a quick dir size ?

-Shawn

[ 06 June 2002, 03:28: Message edited by: Shawn ]

Top
#22684 - 2002-06-06 03:42 AM Re: Dir () did not work well for me !!
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I started timing the recursive UDF [target = C:\WINNT]
shortly after you posted - I will report back when the script is
finished (hopefully tomorrow or the next day).

[ 06 June 2002, 03:43: Message edited by: Shawn ]

Top
#22685 - 2002-06-06 03:50 AM Re: Dir () did not work well for me !!
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
It always interesting that as the thread unfolds, the client's (Donald in this case) needs change. I made a reccommendation based on file count and hmmm, it's not count, it's dir size.

I could knock off a quick script but then the need may change from a total of all dirs to sizes of individual dirs.

You know... that's why I like to write code for myself and not for other ppl. Guess I'm in one of those moods. [Frown]

{edit}
ROFL
I guess I won't wait up...good night.

[ 06 June 2002, 03:53: Message edited by: LLigetfa ]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#22686 - 2002-06-06 04:02 AM Re: Dir () did not work well for me !!
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ummm, my guess is that he took your advise Les, and has left the building.
Top
#22687 - 2002-06-06 04:37 AM Re: Dir () did not work well for me !!
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Just to see what I could provide in Perl, I threw together a little recursing script. Here are the results:

c:\data\scripts>recurse2.pl c:\winnt
Elapsed time: 15 seconds
Files: 10824, Bytes: 1287020642

dir c:\winnt /s took 50 seconds.
Total Files Listed:
10726 File(s) 1,284,268,060 bytes
857 Dir(s) 16,329,506,816 bytes free

I am still checking/debugging but if anyone is interested, I'll compile it and post it on my web site.

c:\data\scripts>recurse2.pl c:\winnt c:\data
Elapsed time: 19 seconds
Files: 13546, Bytes: 2004357973

---------------------------------------------
checking C:\data on my computer:

DOS DIR
Total Files Listed:
2720 File(s) 717,319,707 bytes

c:\data\scripts>recurse2.pl c:\data
Elapsed time: 5 seconds

Not quite sure where the 2 additional files came from. But on another directory the program and DOS Dir match.
Files: 2722, Bytes: 717336963

[ 06 June 2002, 04:45: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#22688 - 2002-06-06 06:43 AM Re: Dir () did not work well for me !!
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I know it's not Kix but in case the Kix efforts for this task don't pan out...

I have posted DirSize.exe that is rather quick and returns the actual number of directories, files, and total bytes used.

DOS's "Dir" command counts all the "." and ".." directories when it counts the number of directories on my W2K Pro SP2 computer. If anyone needs something slightly different let me know.

[ 06 June 2002, 06:44: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#22689 - 2002-06-06 03:12 PM Re: Dir () did not work well for me !!
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Aehm: Why can't we utilize the DIRUSE.EXE in the Windows Resource Kit for this functionality?

Or does it have to be a scripted solution?
_________________________
There are two types of vessels, submarines and targets.

Top
#22690 - 2002-06-06 03:40 PM Re: Dir () did not work well for me !!
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
DOH!! [Embarrassed]

Sometimes life is too simple. At least my little Perl exercise agrees with the DirUse.exe output. FWIW.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#22691 - 2002-06-06 06:18 PM Re: Dir () did not work well for me !!
Anonymous
Unregistered


Hello,
Many thanks to all of yours help, I am gona to try them all to see which is best fit into my environment. I thought about Dos Dir too, but I still need to take that result into an Kix's $variable and continue to compare other condition. Any advice on that as well ?

Like:
$Dirsize = DOS Dir size .. if I jump to dos shell .

Again, thank you all .
Don

Top
#22692 - 2002-06-06 06:26 PM Re: Dir () did not work well for me !!
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Don, just to give pure Kixtart a fighting chance, I slightly modified the above recursive script. It does have exceptable performance for small trees, with known upper limits of a few dozen megabytes. But I always get mildy uncomfortable putting recursive routines into a login script ... probably unjustified, but thats just how I feel.

Luck,

-Shawn

Top
#22693 - 2002-06-06 07:27 PM Re: Dir () did not work well for me !!
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Donald,
If you could fill us in on what exactly your need is rather than have us guess on a "moving target", we could maybe toss something together.

Don't be so cheap with the words.

What info do you need?
number of files
size of files
number of folders
total size of files in these folders (not including subs)
total size of files in these folders (including subs)

How many files/folders we talking about?
What's the total size of these folders?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#22694 - 2002-06-06 08:36 PM Re: Dir () did not work well for me !!
Anonymous
Unregistered


Hello Les and Shawn,
First of all, I would like to say thanks to all of your supports and I felt bad that did not given a full discription in details to you all.
Actually, it is a technically problem in our NT environment.
Lately, we found that there have changed on our current NT image and it causes from
C:\WINNT\Profiles\Default Users 's profile.

Our current image of this profile aproximated 1.2 MB. After a year of full deployment, we have reported that this were changed on number of systems and it caused an issue of SMS deployment in some cases.
My project is to target these systems and resolve the caused.
I am targeting on these systems in comparison of original image and dump to a log file on it local system then I will review it later or at least I can deploy SMS to other system.
A dump.log file on local which are the files that different from the original image.

Again, thanks you all.
Don

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 451 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.124 seconds in which 0.069 seconds were spent on a total of 13 queries. Zlib compression enabled.

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