#207971 - 2013-10-31 02:53 PM
Get size of all users My Documents and Desktops to text file
|
GeorgeLittle
Fresh Scripter
Registered: 2011-02-08
Posts: 47
Loc: UK
|
Hi
So after a while of playing with powershell I am after a kix script that can be run from local machines to do the following;
Find the current logged on user Find the size of my document and desktop folders for all users
record all this infomation in a text file on a network share or a mdb
I have done this using powershell but its so slow and half the machines dont have powershell on them due to age
Cheers again guys
|
Top
|
|
|
|
#207973 - 2013-10-31 04:44 PM
Re: Get size of all users My Documents and Desktops to text file
[Re: ShaneEP]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Here is how I would go about it. There may be an easier way to get the profile list or folder size, but these are the methods that first pop into my head.
Just change the first line to point to whatever text file you want it to be saved in. (Warning, it overwrites existing data, so make sure you dont point to a file thats important.)
$logFile = @ScriptDir+"\Profile Sizes.txt"
$userDir = "%USERPROFILE%"
$profilesDir = SubStr($userDir, 1, InStrRev($userDir, "\"))
$profiles = DirList($profilesDir, 3)
$nul = RedirectOutput($logFile, 1)
For Each $profile in $profiles
If Right($profile, 1) = "\"
? $profile
? "--------------------"
? "Desktop Size: "+FormatNumber(fnGetFolderProp($profile+"Desktop","Size"), 0)
? "Documents Size: "+FormatNumber(fnGetFolderProp($profile+"My Documents","Size"), 0)
? ?
Endif
Next
$nul = RedirectOutput("")
Function fnGetFolderProp($sFldr,$sProp)
Dim $objFSO, $objFldr, $nul
$objFSO = CreateObject("Scripting.FileSystemObject")
If Not VarType($objFSO)=9 Exit 1 EndIf
$objFldr = $objFSO.GetFolder($sFldr)
If Not VarType($objFldr)=9 Exit 3 EndIf
$nul=Execute("$$fnGetFolderProp = $$objFldr."+$sProp)
If VarType($fnGetFolderProp)=0 Exit 87 EndIf
EndFunction
Function dirlist($dirname, optional $options)
dim $filename, $counter, $filepath, $mask
dim $list, $sublist, $subcounter
$counter=-1
$dirname=trim($dirname)
if $dirname=''
$dirname=@CURDIR
endif
if right($dirname,1)='\'
$dirname=left($dirname,len($dirname)-1)
endif
if getfileattr($dirname) & 16
$mask='*.*'
else
$mask=substr($dirname,instrrev($dirname,'\')+1)
$dirname=left($dirname,len($dirname)-len($mask)-1)
endif
redim $list[10]
$filename=dir($dirname+'\'+$mask)
while $filename<>'' and @ERROR=0
if $filename<>'.' and $filename<>'..'
select
case (getfileattr($dirname+'\'+$filename) & 16)
if $options & 1
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'
else
$list[$counter]=$filename+'\'
endif
endif
if ($options & 4)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,$options)
if ubound($sublist)+1
redim preserve $list[ubound($list)+ubound($sublist)+1]
for $subcounter=0 to ubound($sublist)
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
endif
next
endif
endif
case ($options & 2)
$counter=$counter+1
$list[$counter]=$dirname+'\'+$filename
case 1
$counter=$counter+1
$list[$counter]=$filename
endselect
if $counter mod 10
redim preserve $list[$counter+10]
endif
endif
$filename = dir('')
loop
if $counter+1
redim preserve $list[$counter]
else
$list=''
endif
if $mask<>'*.*' and ($options & 4)
$filename=dir($dirname+'\*.*')
while $filename<>'' and @ERROR=0
if $filename<>'.' and $filename<>'..'
if (getfileattr($dirname+'\'+$filename) & 16)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4)
if ubound($sublist)+1
redim preserve $list[ubound($list)+ubound($sublist)+1]
for $subcounter=0 to ubound($sublist)
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
endif
next
endif
endif
endif
$filename = dir('')
loop
endif
if $counter+1
redim preserve $list[$counter]
else
$list=''
endif
$dirlist=$list
endfunction
Edited by ShaneEP (2013-10-31 04:46 PM)
|
Top
|
|
|
|
#207974 - 2013-10-31 04:54 PM
Re: Get size of all users My Documents and Desktops to text file
[Re: ShaneEP]
|
GeorgeLittle
Fresh Scripter
Registered: 2011-02-08
Posts: 47
Loc: UK
|
Thats really cool Shane EP thanks and runs in half the time powershell does
So my current plan would be to deploy this to all the machines. However would it be possible to run it against unc paths ? Just thinking out loud .
|
Top
|
|
|
|
#207976 - 2013-10-31 08:22 PM
Re: Get size of all users My Documents and Desktops to text file
[Re: ShaneEP]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Here is an example of how to log the info to an INI file.
It creates a new section in the file for each Workstation\Account.
$logFile = @ScriptDir+"\Profile Sizes.ini"
$profiles = DirList(SubStr("%USERPROFILE%", 1, InStrRev("%USERPROFILE%", "\")), 3)
For Each $profile in $profiles
If Right($profile, 1) = "\"
$profilename = Split($profile, "\")
$profilename = $profilename[UBound($profilename)-1]
$nul = WriteProfileString($logfile, @WkSta+"\"+$profilename, "Desktop", fnGetFolderProp($profile+"Desktop","Size"))
$nul = WriteProfileString($logfile, @WkSta+"\"+$profilename, "Documents", fnGetFolderProp($profile+"My Documents","Size"))
Endif
Next
Function fnGetFolderProp($sFldr,$sProp)
Dim $objFSO, $objFldr, $nul
$objFSO = CreateObject("Scripting.FileSystemObject")
If Not VarType($objFSO)=9 Exit 1 EndIf
$objFldr = $objFSO.GetFolder($sFldr)
If Not VarType($objFldr)=9 Exit 3 EndIf
$nul=Execute("$$fnGetFolderProp = $$objFldr."+$sProp)
If VarType($fnGetFolderProp)=0 Exit 87 EndIf
EndFunction
Function dirlist($dirname, optional $options)
dim $filename, $counter, $filepath, $mask
dim $list, $sublist, $subcounter
$counter=-1
$dirname=trim($dirname)
if $dirname=''
$dirname=@CURDIR
endif
if right($dirname,1)='\'
$dirname=left($dirname,len($dirname)-1)
endif
if getfileattr($dirname) & 16
$mask='*.*'
else
$mask=substr($dirname,instrrev($dirname,'\')+1)
$dirname=left($dirname,len($dirname)-len($mask)-1)
endif
redim $list[10]
$filename=dir($dirname+'\'+$mask)
while $filename<>'' and @ERROR=0
if $filename<>'.' and $filename<>'..'
select
case (getfileattr($dirname+'\'+$filename) & 16)
if $options & 1
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'
else
$list[$counter]=$filename+'\'
endif
endif
if ($options & 4)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,$options)
if ubound($sublist)+1
redim preserve $list[ubound($list)+ubound($sublist)+1]
for $subcounter=0 to ubound($sublist)
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
endif
next
endif
endif
case ($options & 2)
$counter=$counter+1
$list[$counter]=$dirname+'\'+$filename
case 1
$counter=$counter+1
$list[$counter]=$filename
endselect
if $counter mod 10
redim preserve $list[$counter+10]
endif
endif
$filename = dir('')
loop
if $counter+1
redim preserve $list[$counter]
else
$list=''
endif
if $mask<>'*.*' and ($options & 4)
$filename=dir($dirname+'\*.*')
while $filename<>'' and @ERROR=0
if $filename<>'.' and $filename<>'..'
if (getfileattr($dirname+'\'+$filename) & 16)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4)
if ubound($sublist)+1
redim preserve $list[ubound($list)+ubound($sublist)+1]
for $subcounter=0 to ubound($sublist)
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
endif
next
endif
endif
endif
$filename = dir('')
loop
endif
if $counter+1
redim preserve $list[$counter]
else
$list=''
endif
$dirlist=$list
endfunction
|
Top
|
|
|
|
#207977 - 2013-10-31 09:50 PM
Re: Get size of all users My Documents and Desktops to text file
[Re: ShaneEP]
|
GeorgeLittle
Fresh Scripter
Registered: 2011-02-08
Posts: 47
Loc: UK
|
Cheers shane
can you give me one bit more assistance and show me how I might do it using a list of computer unc paths ?
eg if the text file had
\\computer1\c$\documents and settings\ \\computer2\c$\documents and settings\ \\computer3\c$\documents and settings\
I think that I could load the file using Glens FILOio udf
|
Top
|
|
|
|
#207983 - 2013-11-01 04:53 PM
Re: Get size of all users My Documents and Desktops to text file
[Re: Glenn Barnas]
|
GeorgeLittle
Fresh Scripter
Registered: 2011-02-08
Posts: 47
Loc: UK
|
so heres my go at it still not working
$aTargets = FileIO('c:\scripts\hosts.txt', 'R')
For Each $Host in $aTargets
; run code to query each $Host value
If Ping($Host)
$HostPath = '\\' + $Host + 'C$\users'
'Processing ' $HostPath ? ; for debugging or status reporting
; run any necessary command using $HostPath to reference the target path
$logFile = @ScriptDir+"\Profile Sizes.ini"
$profiles = DirList($HostPath)
For Each $profile in $profiles
If Right($profile, 1) = "\"
$profilename = Split($profile, "\")
$profilename = $profilename[UBound($profilename)-1]
$nul = WriteProfileString($logfile, @WkSta+"\"+$profilename, "Desktop", fnGetFolderProp($profile+"Desktop","Size"))
$nul = WriteProfileString($logfile, @WkSta+"\"+$profilename, "Documents", fnGetFolderProp($profile+"My Documents","Size"))
Endif
Next
Function fnGetFolderProp($sFldr,$sProp)
Dim $objFSO, $objFldr, $nul
$objFSO = CreateObject("Scripting.FileSystemObject")
If Not VarType($objFSO)=9 Exit 1 EndIf
$objFldr = $objFSO.GetFolder($sFldr)
If Not VarType($objFldr)=9 Exit 3 EndIf
$nul=Execute("$$fnGetFolderProp = $$objFldr."+$sProp)
If VarType($fnGetFolderProp)=0 Exit 87 EndIf
EndFunction
Function dirlist($dirname, optional $options)
dim $filename, $counter, $filepath, $mask
dim $list, $sublist, $subcounter
$counter=-1
$dirname=trim($dirname)
if $dirname=''
$dirname=@CURDIR
endif
if right($dirname,1)='\'
$dirname=left($dirname,len($dirname)-1)
endif
EndIf
Next
;FUNCTION Ping()
;
;AUTHOR Jochen Polster (jochenDOTpolsterATgmxDOTnet)
;
;VERSION HISTORY 1.0 - 11/24/2001 Initial Release
; 1.1 - 11/11/2004 Fixed problems regarding spaces in folder names
; of script directory (thanks to Alistair)
; 1.2 - 12/07/2004 Fixed for NoVarsInStrings and Explicit on
;
;ACTION Pings the Computer specified, or returns its ip address (Wins Resolved)
;
;SYNTAX Ping(Computer,GetIP,[LoopCount],[Timeout])
;
;PARAMETERS Computer (Required)
; - String value representing the Computer to ping
;
; GetIp (Required)
; - If specified (1), the function will return the ip-address
; of specified Computer rather than pinging it ...
; Has to be 0 if you want to check for reply !
;
; LoopCount (Optional but useful !)
; - Integer value representing the number of times
; the Computer shall be pinged
;
; Timeout (Optional)
; - if ommited the Computer gets pinged with the default
; timeout (1s) and default retries (4)
;
;REMARKS If there is a reply the function will return immediately with 1
; so it could be faster not specifiying a timeout.
;
;RETURNS 0 - No reply
; 1 - Ping reply
; Optional - ip address of specified Computer
;
;DEPENDENCIES None
;
;EXAMPLES call "path\Ping.udf"
; if Ping("www.microsoft.com",0,12,5000) ;pings for max. 60 seconds
; run "%ComSpec% /c start www.microsoft.com"
; else
; 'Site isn't available ' ?
; endif
; if Ping("www.microsoft.com",0,15) ;pings also for max. 60 seconds
; run "%ComSpec% /c start www.microsoft.com"
; else
; 'Site isn't available ' ?
; endif
; $ip = Ping("www.microsoft.com",1)
; $ip ?
function Ping($Computer,$GetIP,optional $LoopCount,optional $TimeOut)
if $GetIP
dim $ip, $ipfile, $
$ipfile = @scriptdir + '\ip.txt'
shell '%Comspec% /q /e:1024 /c for /F "tokens=2 delims=[]" %%i IN ('+ chr(39)
+ '"ping ' + $Computer + ' -n 1 | find "]""' + chr(39) + ') do echo %%i >"' + $ipfile + '"'
$ = open(10,$ipfile,2) $ip = readline(10) $ = close(10) del $ipfile
if $ip
$Ping = $ip
else
$Ping = 'Bad IP address ' + $Computer + '!'
endif
exit 0
else
if $TimeOut
for $c = 0 to $LoopCount
shell '%Comspec% /C ping ' + $Computer + ' -n 1 -w ' + $TimeOut + ' | find /C "TTL=" > nul'
if @error = 0
$Ping = 1
exit 0
endif
next
else
for $c = 0 to $LoopCount
shell '%Comspec% /C ping ' + $Computer + ' | find /C "TTL=" > nul'
if @error = 0
$Ping = 1
exit 0
endif
next
endif
$Ping = 0
endif
endfunction
Edited by Mart (2013-11-03 02:29 PM) Edit Reason: Please use code tags when posting code.
|
Top
|
|
|
|
#207987 - 2013-11-01 06:08 PM
Re: Get size of all users My Documents and Desktops to text file
[Re: ShaneEP]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Give this a shot...see what you get. Also Im assuming the Host paths are displaying correctly to the screen when it runs? Is there a backslash at the end of the hosts in the file?
This $HostPath = '\\' + $Host + 'C$\users' may need to be $HostPath = '\\' + $Host + '\C$\users'
$aTargets = FileIO('c:\scripts\hosts.txt', 'R')
For Each $Host in $aTargets
; run code to query each $Host value
If Ping($Host)
$HostPath = '\\' + $Host + 'C$\users'
'Processing ' $HostPath ? ; for debugging or status reporting
; run any necessary command using $HostPath to reference the target path
$logFile = @ScriptDir+"\Profile Sizes.ini"
$profiles = DirList($HostPath, 3)
For Each $profile in $profiles
If Right($profile, 1) = "\"
$profilename = Split($profile, "\")
$profilename = $profilename[UBound($profilename)-1]
$nul = WriteProfileString($logfile, $Host+"\"+$profilename, "Desktop", fnGetFolderProp($profile+"Desktop","Size"))
$nul = WriteProfileString($logfile, $Host+"\"+$profilename, "Documents", fnGetFolderProp($profile+"My Documents","Size"))
Endif
Next
Endif
Next
Function fnGetFolderProp($sFldr,$sProp)
Dim $objFSO, $objFldr, $nul
$objFSO = CreateObject("Scripting.FileSystemObject")
If Not VarType($objFSO)=9 Exit 1 EndIf
$objFldr = $objFSO.GetFolder($sFldr)
If Not VarType($objFldr)=9 Exit 3 EndIf
$nul=Execute("$$fnGetFolderProp = $$objFldr."+$sProp)
If VarType($fnGetFolderProp)=0 Exit 87 EndIf
EndFunction
Function dirlist($dirname, optional $options)
dim $filename, $counter, $filepath, $mask
dim $list, $sublist, $subcounter
$counter=-1
$dirname=trim($dirname)
if $dirname=''
$dirname=@CURDIR
endif
if right($dirname,1)='\'
$dirname=left($dirname,len($dirname)-1)
endif
if getfileattr($dirname) & 16
$mask='*.*'
else
$mask=substr($dirname,instrrev($dirname,'\')+1)
$dirname=left($dirname,len($dirname)-len($mask)-1)
endif
redim $list[10]
$filename=dir($dirname+'\'+$mask)
while $filename<>'' and @ERROR=0
if $filename<>'.' and $filename<>'..'
select
case (getfileattr($dirname+'\'+$filename) & 16)
if $options & 1
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'
else
$list[$counter]=$filename+'\'
endif
endif
if ($options & 4)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,$options)
if ubound($sublist)+1
redim preserve $list[ubound($list)+ubound($sublist)+1]
for $subcounter=0 to ubound($sublist)
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
endif
next
endif
endif
case ($options & 2)
$counter=$counter+1
$list[$counter]=$dirname+'\'+$filename
case 1
$counter=$counter+1
$list[$counter]=$filename
endselect
if $counter mod 10
redim preserve $list[$counter+10]
endif
endif
$filename = dir('')
loop
if $counter+1
redim preserve $list[$counter]
else
$list=''
endif
if $mask<>'*.*' and ($options & 4)
$filename=dir($dirname+'\*.*')
while $filename<>'' and @ERROR=0
if $filename<>'.' and $filename<>'..'
if (getfileattr($dirname+'\'+$filename) & 16)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4)
if ubound($sublist)+1
redim preserve $list[ubound($list)+ubound($sublist)+1]
for $subcounter=0 to ubound($sublist)
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
endif
next
endif
endif
endif
$filename = dir('')
loop
endif
if $counter+1
redim preserve $list[$counter]
else
$list=''
endif
$dirlist=$list
endfunction
Function Ping($Computer,$GetIP,optional $LoopCount,optional $TimeOut)
if $GetIP
dim $ip, $ipfile, $
$ipfile = @scriptdir + '\ip.txt'
shell '%Comspec% /q /e:1024 /c for /F "tokens=2 delims=[]" %%i IN ('+ chr(39)
+ '"ping ' + $Computer + ' -n 1 | find "]""' + chr(39) + ') do echo %%i >"' + $ipfile + '"'
$ = open(10,$ipfile,2) $ip = readline(10) $ = close(10) del $ipfile
if $ip
$Ping = $ip
else
$Ping = 'Bad IP address ' + $Computer + '!'
endif
exit 0
else
if $TimeOut
for $c = 0 to $LoopCount
shell '%Comspec% /C ping ' + $Computer + ' -n 1 -w ' + $TimeOut + ' | find /C "TTL=" > nul'
if @error = 0
$Ping = 1
exit 0
endif
next
else
for $c = 0 to $LoopCount
shell '%Comspec% /C ping ' + $Computer + ' | find /C "TTL=" > nul'
if @error = 0
$Ping = 1
exit 0
endif
next
endif
$Ping = 0
endif
EndFunction
|
Top
|
|
|
|
#207995 - 2013-11-04 11:02 AM
Re: Get size of all users My Documents and Desktops to text file
[Re: Glenn Barnas]
|
GeorgeLittle
Fresh Scripter
Registered: 2011-02-08
Posts: 47
Loc: UK
|
So when I run it I get an Error Expected ')'! Line 1
|
Top
|
|
|
|
#207998 - 2013-11-04 06:12 PM
Re: Get size of all users My Documents and Desktops to text file
[Re: ShaneEP]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
$aTargets = FileIO('c:\scripts\hosts.txt', 'R')
For Each $Host in $aTargets
; run code to query each $Host value
If Ping($Host)
$HostPath = '\\' + $Host + '\C$\users'
'Processing ' $HostPath ? ; for debugging or status reporting
; run any necessary command using $HostPath to reference the target path
$logFile = @ScriptDir+"\Profile Sizes.ini"
$profiles = DirList($HostPath, 3)
For Each $profile in $profiles
If Right($profile, 1) = "\"
$profilename = Split($profile, "\")
$profilename = $profilename[UBound($profilename)-1]
$nul = WriteProfileString($logfile, $Host+"\"+$profilename, "Desktop", fnGetFolderProp($profile+"Desktop","Size"))
$nul = WriteProfileString($logfile, $Host+"\"+$profilename, "Documents", fnGetFolderProp($profile+"My Documents","Size"))
Endif
Next
Endif
Next
Function fnGetFolderProp($sFldr,$sProp)
Dim $objFSO, $objFldr, $nul
$objFSO = CreateObject("Scripting.FileSystemObject")
If Not VarType($objFSO)=9 Exit 1 EndIf
$objFldr = $objFSO.GetFolder($sFldr)
If Not VarType($objFldr)=9 Exit 3 EndIf
$nul=Execute("$$fnGetFolderProp = $$objFldr."+$sProp)
If VarType($fnGetFolderProp)=0 Exit 87 EndIf
EndFunction
Function dirlist($dirname, optional $options)
dim $filename, $counter, $filepath, $mask
dim $list, $sublist, $subcounter
$counter=-1
$dirname=trim($dirname)
if $dirname=''
$dirname=@CURDIR
endif
if right($dirname,1)='\'
$dirname=left($dirname,len($dirname)-1)
endif
if getfileattr($dirname) & 16
$mask='*.*'
else
$mask=substr($dirname,instrrev($dirname,'\')+1)
$dirname=left($dirname,len($dirname)-len($mask)-1)
endif
redim $list[10]
$filename=dir($dirname+'\'+$mask)
while $filename<>'' and @ERROR=0
if $filename<>'.' and $filename<>'..'
select
case (getfileattr($dirname+'\'+$filename) & 16)
if $options & 1
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'
else
$list[$counter]=$filename+'\'
endif
endif
if ($options & 4)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,$options)
if ubound($sublist)+1
redim preserve $list[ubound($list)+ubound($sublist)+1]
for $subcounter=0 to ubound($sublist)
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
endif
next
endif
endif
case ($options & 2)
$counter=$counter+1
$list[$counter]=$dirname+'\'+$filename
case 1
$counter=$counter+1
$list[$counter]=$filename
endselect
if $counter mod 10
redim preserve $list[$counter+10]
endif
endif
$filename = dir('')
loop
if $counter+1
redim preserve $list[$counter]
else
$list=''
endif
if $mask<>'*.*' and ($options & 4)
$filename=dir($dirname+'\*.*')
while $filename<>'' and @ERROR=0
if $filename<>'.' and $filename<>'..'
if (getfileattr($dirname+'\'+$filename) & 16)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4)
if ubound($sublist)+1
redim preserve $list[ubound($list)+ubound($sublist)+1]
for $subcounter=0 to ubound($sublist)
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
endif
next
endif
endif
endif
$filename = dir('')
loop
endif
if $counter+1
redim preserve $list[$counter]
else
$list=''
endif
$dirlist=$list
endfunction
Function FileIO($_File, $_Mode, OPTIONAL $_aData, OPTIONAL $_Opts)
Dim $_ ; temp var
Dim $_I ; index pointer
Dim $_Fp ; file pointer
Dim $_Fm ; file I/O mode
Dim $_Term ; line terminator
Dim $_NoNul ; Null line suppression flag
Dim $_FTerm ; final line term
Dim $_Prog ; Progress indicator flag
$FileIO = 0 ; return fail by default
; set the process options
$_Term = IIf($_Opts & 1, Chr(10), @CRLF)
$_NoNul = IIf($_Opts & 2, 1, 0)
$_FTerm = IIf($_Opts & 4, '', $_Term)
$_Prog = IIf($_Opts & 8, 1, 0)
; validate the mode & set the I/O mode
$_Mode = Left($_Mode, 1)
Select
Case $_Mode = 'R' ; read
$_Fm = 2
Case $_Mode = 'W' ; write/create
If VarType($_aData) < 8192
Exit 87 ; exit with error if Write/Create mode and no data
EndIf
$_Fm = 5
If Exist($_File) ; remove any existing file if not in Append mode
Del $_File
EndIf
Case $_Mode = 'A' ; append
If VarType($_aData) < 8192
Exit 87 ; exit with error if Write/Append mode and no data
EndIf
$_Fm = 5
Case 1 ; invalid mode
Exit 87
EndSelect
; locate an available file handle
$_Fp = FreeFileHandle
If Not $_Fp
Exit 1
EndIf
; Open the file in the defined input or output mode - exit if the open fails
$_ = Open($_Fp, $_File, $_Fm)
If @ERROR Exit @ERROR EndIf
If $_Fm = 2 ; read file
ReDim $_aData[499] ; start w/ 500 lines
$_I = -1
$_ = ReadLine($_Fp)
While Not @ERROR
$_I = $_I + 1
$_aData[$_I] = $_
If $_I > 1 And $_I Mod 499 = 0
ReDim Preserve $_aData[$_I + 500]
If $_Prog '.' EndIf ; progress marker
EndIf
$_ = ReadLine($_Fp)
Loop
$_ = Close($_Fp)
ReDim Preserve $_aData[$_I]
If $_Prog '. ' EndIf
$FileIO = $_aData
Exit 0
Else ; write file
For $_I = 0 to UBound($_aData) - 1
If $_NoNul
If $_aData[$_I] ; write if not null
$_ = WriteLine($_FP, $_aData[$_I] + $_Term)
EndIf
Else ; write always
$_ = WriteLine($_FP, $_aData[$_I] + $_Term)
EndIf
If $_I > 1 And $_I Mod 499 = 0 And $_Prog '.' EndIf
Next
; write last line
If $_NoNul
If $_aData[$_I] ; write if not null
$_ = WriteLine($_FP, $_aData[$_I] + $_FTerm)
EndIf
Else ; write always
$_ = WriteLine($_FP, $_aData[$_I] + $_FTerm)
EndIf
$_ = Close($_Fp)
$FileIO = 1 ; show a completed write
If $_Prog '. ' EndIf
Exit 0
EndIf
EndFunction
Function Ping($_Host, OPTIONAL $_Flag, OPTIONAL $_Wait)
Dim $_oExec ; WSH Object
Dim $_Tries ; # of times to ping
Dim $_Timeout ; Ping timeout value
Dim $_Response ; Response Flag
Dim $_Line ; Line returned from command string
Dim $_Cmd ; first part of command string
Dim $_Count ; current ping count
$_Flag = Val($_Flag) ; determine what to do
$_Wait = Val($_Wait) ;
$_Tries = 1 ; one ping
$_Timeout = 1000 ; 1 second timeout
; set timeout if Wait is non-zero
If $_Wait > 0
$_Timeout = $_Wait
EndIf
If $_FLAG > 0 ; Multiple pings - return on first reply
$_Tries = $_FLAG
EndIf
; Ping the host $_Tries times, but only until a response is received
$_Count = 0
; search for reply from host during PING
$_Cmd = '%COMSPEC% /c ping.exe -4 -n 1 -w ' + $_Timeout + ' ' + $_Host
If $_Flag < 0
$_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Pinging"'
Else
$_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Reply" | %SystemRoot%\System32\Find "TTL="'
EndIf
Do
$_oExec = CreateObject("WScript.Shell").Exec($_Cmd)
If Not VarType($_oExec)=9 $Ping = 'WScript.Shell Exec Unsupported' Exit 10 EndIf
$_Line = Split(Join(Split($_oExec.StdOut.ReadAll + $_oExec.StdErr.ReadAll,CHR(13)),''),CHR(10))[0]
$_Response = IIf($_Line, 1, 0)
If $_Response
$_Count = $_Tries
EndIf
$_Count = $_Count + 1
If $_Count < $_Tries Sleep 0.25 EndIf
Until $_Count >= $_Tries
; If FLAG >= 0, return success/failure - otherwise return IP address
If $_FLAG >= 0
$Ping = $_Response
Else
If Not $_Response
$Ping = '0.0.0.0'
Else
; In this mode we return the IP address - we should have the HOSTNAME
; handle the 'duh' factor for times when we get the IP address instead!
If InStr($_Line,'[') > 0
$Ping= Split(Join(Split($_Line,']',-1),'['), '[')[1]
Else
$Ping = Split(Split($_Line,' ',-1)[1], ':')[0]
EndIf
EndIf
EndIf
Exit Not $_Response ; set the error code
EndFunction
|
Top
|
|
|
|
#207999 - 2013-11-05 10:04 AM
Re: Get size of all users My Documents and Desktops to text file
[Re: GeorgeLittle]
|
GeorgeLittle
Fresh Scripter
Registered: 2011-02-08
Posts: 47
Loc: UK
|
That is now working a treat ! Thanks so much guys
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 507 anonymous users online.
|
|
|