Peter Fry
(Getting the hang of it)
2004-08-16 11:04 AM
Seach machines hardrives for a file between 2800kb and 2900kb

hi

is it possible to do this? i can't seem to even get started on this one....

i need to search a PCs local drives for a file between these two sizes, damn management.........

Pete


LonkeroAdministrator
(KiX Master Guru)
2004-08-16 11:35 AM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

depends how good you wanna do it.
if it's one time job (meaning, not all the time) and on one pc at a time, something like this should do the job:

removed


LonkeroAdministrator
(KiX Master Guru)
2004-08-16 11:40 AM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

hmm...
that does not work remotely.
so skip it


LonkeroAdministrator
(KiX Master Guru)
2004-08-16 11:53 AM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

ok, this works:

for each $file in drivescan("\\pc2lonkero\c$")
$file ?
next
get $

function drivescan($drive,optional $reserved)
dim $shell,$item,$root
if not $reserved redim $drivescan $root=$drive endif
$shell=createobject("shell.application")
for each $item in $shell.namespace($drive).items
if $item.isfolder
$drivescan=$drivescan+drivescan($item.path,1)
endif
if 2799<$item.size and 2901>$item.size
$drivescan=$drivescan+$item.path+chr(10)
endif
next
if $drive=$root
$drivescan=split($drivescan,chr(10))
redim preserve $drivescan[ubound($drivescan)-1]
endif
endfunction


Peter Fry
(Getting the hang of it)
2004-08-16 11:58 AM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

thx this is working great

can i get the output to put the size of the file in as well?
any ideas?


JochenAdministrator
(KiX Supporter)
2004-08-16 12:07 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

Quote:

ok, this works:
<table width="500" bgcolor="black" fontcolor="red"><tr><td>
for each $file in drivescan("\\pc2lonkero\c$")
$file ?
next
get $

function drivescan($drive,optional $reserved)
dim $shell,$item,$root
if not $reserved redim $drivescan $root=$drive endif
$shell=createobject("shell.application")
for each $item in $shell.namespace($drive).items
if $item.isfolder
$drivescan=$drivescan+drivescan($item.path,1)
endif
if 2799<$item.size and 2901>$item.size
$drivescan=$drivescan+$item.path+chr(10)
endif
next
if $drive=$root
$drivescan=split($drivescan,chr(10))
redim preserve $drivescan[ubound($drivescan)-1]
endif
endfunction
</td></tr></table>




this appears like the good olde black eagle on black background to me (working with a LCD display and Maxthon beta (fka MyIE2)



LonkeroAdministrator
(KiX Master Guru)
2004-08-16 12:08 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

ja.
if there is not a single such file on the drive/dir you are scanning, that happens.

change it to something like:
if ubound($drivescan)>0
redim
endif


Peter Fry
(Getting the hang of it)
2004-08-16 12:11 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

you're a star

working with it now

any idea how to get the file size to output on the same line as the file name?

Pete


LonkeroAdministrator
(KiX Master Guru)
2004-08-16 12:11 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

wonder what you mumble?
I work with LCD display too.
the table has 2 colors.
if your display can't show black&white graphics and text, I recommend doing something to it

or what the heck?
me not sure...
black eagle, black black... what?


Peter Fry
(Getting the hang of it)
2004-08-16 12:14 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

well i have to highlight the text to be able to read it when you put it on the black background, not complaining as you're writing some good code (far better than i can do)

LonkeroAdministrator
(KiX Master Guru)
2004-08-16 12:16 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

oh, you boys have the default template or something...
fixing...


LonkeroAdministrator
(KiX Master Guru)
2004-08-16 12:20 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

better?


JochenAdministrator
(KiX Supporter)
2004-08-16 12:30 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

yeah ... at least readyble now (don't mumble about style or so... looking good anyway)

Peter Fry
(Getting the hang of it)
2004-08-16 12:34 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

yep much better can read now

any ideas on the file size showing?


LonkeroAdministrator
(KiX Master Guru)
2004-08-16 12:44 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

jochen, I just didn't get ya.
in my black&blue template it showed just fine so had no idea what you bitching about

peter, what you mean about showing?
you wanna see the size too?


Peter Fry
(Getting the hang of it)
2004-08-16 12:51 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

yes please something like
c:\temp\test.doc 2850

or something simular

just so i can do some easier checking


LonkeroAdministrator
(KiX Master Guru)
2004-08-16 01:21 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

so, you don't want all the files that are of some size but you want the sizes of all files on all directories on some harddisk?
can't see any usage for such...
but, if you want manual method, you shall get it...
still can't understand why.


LonkeroAdministrator
(KiX Master Guru)
2004-08-16 01:27 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

k, try this:

drivescan("\\pc2lonkero\c$")
get $

function drivescan($drive,optional $reserved)
dim $shell,$item,$root
if not $reserved redim $drivescan $root=$drive endif
$shell=createobject("shell.application")
for each $item in $shell.namespace($drive).items
if $item.isfolder
drivescan($item.path,1)
endif
if 2799<$item.size and 2901>$item.size
$item.size " " $item.path ?
endif
next
endfunction


this what you wanted?


Peter Fry
(Getting the hang of it)
2004-08-16 01:28 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

well what i want is this
i'll try and make it as easy as possible

given a list of machines (prolly around 300)
search there local harddrives for a file that is size 2546176 in size (but as some people have edited this file i wanted to capture the ones that were greater than this up to say around 2800000)
list the files that it finds with the size
so i see
c:\test.doc 2546176
c:\temp\test.doc 2734000

what i'm going to need but i think i can do this is
get the following output
machine=testpc
c:\test.doc 2546176
c:\temp\test.doc 2734000
-----------------
machine=testpc2
-----------------
machine=testpc3
-----------------
machine=testpc5
c:\test.doc 2546176
c:\temp\test.doc 2734000

so i can see which machines have the file size and which ones don't

does that make sense?

basically a very sensitive file from HR has been leaked out to the network and the management are asking me to see if i can locate any copies on peoples harddrives

people have renamed this file and some might have changed the size buy adding a few extra characters

does this make sense now?


Peter Fry
(Getting the hang of it)
2004-08-16 02:21 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

one thing when i run this on a large drive i get
Stack overflow exception.
The common cause for this type of exception is an endless recursive loop.
Please check your script(s) for endless loops.
is there anyway to stop this?


Richard H.Administrator
(KiX Supporter)
2004-08-16 02:56 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

Most common cause is forgetting to avoid the "." and ".." entries (self and parent).

Not in this case though

It could be a memory leak.

Try adding "$shell=0" just before the function exit.


Peter Fry
(Getting the hang of it)
2004-08-16 03:12 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

trying this now will get back to you ASAP

hopefully this will work

thanks for help


LonkeroAdministrator
(KiX Master Guru)
2004-08-16 03:15 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

richard, I was thinking about running out of memory...
this function is quite memory expensive on large drives...


Peter Fry
(Getting the hang of it)
2004-08-16 03:18 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

the machine i'm working on as 1.5GB of RAM and there is lots free so i can't see it is running out of ram..... well at least i think it isn't

Peter Fry
(Getting the hang of it)
2004-08-16 03:23 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

the kix32.exe process got to around 52mb and then crashed with the same message as b4

any more ideas?

i had over 1200mb of memory free at this point as well


LonkeroAdministrator
(KiX Master Guru)
2004-08-16 03:31 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

what version of kix?

Peter Fry
(Getting the hang of it)
2004-08-16 03:34 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

kix32.exe version 4.22

Richard H.Administrator
(KiX Supporter)
2004-08-16 03:39 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

Try this:
Code:
Break ON

$=SetOption("WrapAtEOL","ON")

Global $iRecursiveDepth
Global $oShell

$oShell=createobject("shell.application")

drivescan("\\CLIENTPC\c$")
"Done." ?

Function drivescan($sPath)
Dim $oItem

For Each $oItem in $oShell.namespace($sPath).items
If $oItem.isfolder
$iRecursiveDepth=$iRecursiveDepth+1
"New recursion <"+$iRecursiveDepth+"> "+$oItem.path ?
drivescan($oItem.path)
$iRecursiveDepth=$iRecursiveDepth-1
EndIf
Next
Exit 0
EndFunction



Peter Fry
(Getting the hang of it)
2004-08-16 03:45 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

where would i add the filesize required in this new script?

LonkeroAdministrator
(KiX Master Guru)
2004-08-16 03:47 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

you don't need it.
try running script and see does it crash.

if it does, tell us what is the last line on console.
if it doesn't, we (richard) will rethink.


Peter Fry
(Getting the hang of it)
2004-08-16 03:49 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

k i'm running it now

thanks for all this help!


Richard H.Administrator
(KiX Supporter)
2004-08-16 03:53 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

The script is a "debug" version, to try and get a handle on how and why you are getting the exception.

You need to ensure it runs through to completion before you start to worry about adding other features.

Something like this will do you however:
Code:
Break ON
$=SetOption("WrapAtEOL","ON")

Global $iRecursiveDepth
Global $oShell

$oShell=createobject("shell.application")

drivescan("\\SGB007968\c$")
"Done." ?

Function drivescan($sPath)
Dim $oItem

For Each $oItem in $oShell.namespace($sPath).items
If $oItem.isfolder
$iRecursiveDepth=$iRecursiveDepth+1
"New recusion <"+$iRecursiveDepth+"> "+$oItem.path ?
drivescan($oItem.path)
$iRecursiveDepth=$iRecursiveDepth-1
Else
If 2799<$oItem.size AND 2901>$oItem.size
"*** File match "+$oItem.size+" "+$oItem.path ?
EndIf
EndIf
Next
Exit 0
EndFunction



Peter Fry
(Getting the hang of it)
2004-08-16 03:56 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

ok running code - i did it wrong first time i'll let you know what happens

Peter Fry
(Getting the hang of it)
2004-08-16 04:10 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

New recursion <1111> \\Homesrv\aam1402$\old profile\Application Data\Microsoft\Office\Shortcut Bar\Office

thats the last line in the list


LonkeroAdministrator
(KiX Master Guru)
2004-08-16 04:10 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

remember, if it crashes, wanna know where.

LonkeroAdministrator
(KiX Master Guru)
2004-08-16 04:11 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

k.
that's nice info, thanks.


Richard H.Administrator
(KiX Supporter)
2004-08-16 04:40 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

Holy Cow!

Well, you've got a loop in there alright. The recursion level should be about 10 for that directory path depth!

Perhaps you are picking up a shortcut to a directory or share name which refers back to a higher level directory. You will need to redirect the output to a file or something, and spot when it goes haywire.

Basically, the recursion depth should be the same as the directory depth below your start directory.


Peter Fry
(Getting the hang of it)
2004-08-17 09:34 AM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

ok i think i've sorted out that problem

it had found a "nethood" directory with loads of shortcuts in

for a quick fix i removed this directory (it was nothing important)

now to see what happens next

thanks for all the help so far !!


Peter Fry
(Getting the hang of it)
2004-08-17 09:59 AM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

ok i've found the problem

how can i get it so if the script finds a folder called "NetHood" it doesn't go down and look in this folder?

Pete


Richard H.Administrator
(KiX Supporter)
2004-08-17 11:10 AM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

Simplest is probably to change this line:
Code:
If $oItem.isfolder



to read:
Code:
If $oItem.isfolder AND Not InStr($oItem.path,"Nethood")



NB, if shortcuts are the problem you may well find them in other folders, so you may want to consider finding a smarter method.


Peter Fry
(Getting the hang of it)
2004-08-17 12:24 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

thx richard, i'll see if this does the trick first....

hopefully it will other wise it will get more complicated

thanks again

Pete


LonkeroAdministrator
(KiX Master Guru)
2004-08-17 01:19 PM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

$item.islink

denotes shortcut, so could try:

if $item.isfolder and not $item.islink


Peter Fry
(Getting the hang of it)
2004-08-19 09:56 AM
Re: Seach machines hardrives for a file between 2800kb and 2900kb

many thx that islink worked a treat

thx again