Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Count files in directory (and subdirectory) on remote servers and output to text file

289 views
Skip to first unread message

butt...@gmail.com

unread,
Feb 27, 2013, 12:29:25 PM2/27/13
to
OK.. so I have this. It does great at counting the number of files in c:\temp and it's subfolders. But it pops it up in a msgbox.

What I really need is something that will
a) read a list of remote computers (e.g., c:\servers.txt)
b) count the files in a folder (and subfolders) e.g., c:\temp
c)output all of this to a text file (output.txt) thusly

Server Number of Files
LukeSky 12
DarthV 9
HansSolo 27
PrincessL 4

etc etc.. here is what I'm starting with.. obviously, I don't know what I'm doing. Any help appreciated.


code:
Option Explicit

dim fs, a

Set fs = CreateObject("scripting.filesystemobject")


' count files in temp directory
Msgbox CountFiles ("c:\temp")


Function CountFiles (ByVal StrFolder)
Dim ParentFld
Dim SubFld
Dim IntCount

Set ParentFld = fs.GetFolder (StrFolder)

IntCount = ParentFld.Files.Count

For Each SubFld In ParentFld.SubFolders

IntCount = IntCount + CountFiles(SubFld.Path)
Next

Countfiles = IntCount
End Function

Auric__

unread,
Feb 27, 2013, 4:11:59 PM2/27/13
to
buttsnet wrote:

> OK.. so I have this. It does great at counting the number of files in
> c:\temp and it's subfolders. But it pops it up in a msgbox.
>
> What I really need is something that will
> a) read a list of remote computers (e.g., c:\servers.txt)
> b) count the files in a folder (and subfolders) e.g., c:\temp
> c)output all of this to a text file (output.txt) thusly
>
> Server Number of Files
> LukeSky 12
> DarthV 9
> HansSolo 27
> PrincessL 4
>
> etc etc.. here is what I'm starting with.. obviously, I don't know what
> I'm doing. Any help appreciated.
[snip]

To write to a text file, it's like this:

Const ForWriting = 2
Set fo = FSO.OpenTextFile(filename, ForWriting, True)
fo.Write "string"
fo.WriteLine "string"
fo.Close

The args for OpenTextFile are:
1. Filename to open.
2. Mode (read, read, etc).
3. Create file if doesn't exist?

The .WriteLine method automagically adds a newline at the end of the string;
.Write does not.

As for retreiving the server names and whatnot, I have no clue. I'm not real
big on VBS; specifically, I don't know how to do what you need without
calling APIs (which don't work under VBS AFAIK). It might be as simple as:

Set ParentFld = fs.GetFolder ("\\LukeSky\C$\temp")

...but I don't have a Windows server set up to test against.

Unfortunately, I'm pretty sure *everybody* has abandoned this group. You'll
probably get better replies from a forum somewhere on the www.

--
You can cause havoc without being a hacker,
and you can be a hacker without causing havoc.

Mayayana

unread,
Feb 27, 2013, 4:23:04 PM2/27/13
to
| Unfortunately, I'm pretty sure *everybody* has abandoned this group.
You'll
| probably get better replies from a forum somewhere on the www.
|

We're still here, but I was waiting for someone else
to answer. Like you, I know the code but have no idea
how one accesses remote machines via WSH.


Auric__

unread,
Feb 27, 2013, 4:24:07 PM2/27/13
to
I wrote:

> 2. Mode (read, read, etc).

Derp. "read, WRITE, etc."

--
- Sir, if you crave adventure, come with me!
- Actually, I'm allergic to adventure.
- Great! The swelling will make it all that much more adventurous!

Auric__

unread,
Feb 27, 2013, 4:24:56 PM2/27/13
to
I'm sure it's some trivially easy task for people that know what they're
doing. Too bad I'm not one of them.

--
Think a minute, even if it hurts.

Todd Vargo

unread,
Feb 27, 2013, 4:52:34 PM2/27/13
to
For a small number its easy enough to list them in the script. For
larger numbers, one can either read from a complete list of known
workstations (to document which are offline), or obtain a list of only
those online by modifying the solution in the following post to suit
individual needs.

(All one line...)
http://www.edugeek.net/forums/how-do-you-do/50377-list-computers-domain-text-file-vbs.html

Google IS your friend.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
0 new messages