#76549 - 2003-08-30 01:43 AM
DirList with Owner of files
|
Richie19Rich77
Seasoned Scripter
   
Registered: 2002-08-16
Posts: 624
Loc: London, England
|
Hi Everyone
Been doing some digging into M$ site and have created a much faster code that lists the owner of each file in a given folder.
code:
$folderName = "C:\Winnt" ShowFileList($folderName)
Function ShowFileList($folderName) $FileList = CreateObject("Scripting.FileSystemObject").GetFolder($folderName).Files For Each $FileListArray In $FileList $Filename = $FolderName+"\"+$FileListArray.name $WMIFileSecSetting = GetObject ("Winmgmts:").ExecQuery("ASSOCIATORS OF {win32_LogicalFileSecuritySetting='"+$FileName+"'}WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner") For Each $Object In $WMIFileSecSetting ? "FileName: "+$FileListArray.name+" Owner: "+$Object.AccountName Next Next EndFunction
and a basic DirList - Looks super fast to me.
code:
$folderName = "C:\Winnt" ShowFileList($folderName)
Function ShowFileList($folderName) $FileList = CreateObject("Scripting.FileSystemObject").GetFolder($folderName).Files For Each $FileListArray In $FileList ? "FileName: "+$FileListArray.name Next EndFunction
[ 30. August 2003, 01:44: Message edited by: Richard Farthing ]
|
|
Top
|
|
|
|
#76550 - 2003-08-30 01:47 AM
Re: DirList with Owner of files
|
Richie19Rich77
Seasoned Scripter
   
Registered: 2002-08-16
Posts: 624
Loc: London, England
|
Hmm the second bit of code is not that much faster , It is much faster when doing a DirList and checking the owner.
|
|
Top
|
|
|
|
#76552 - 2003-08-30 04:10 PM
Re: DirList with Owner of files
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
for each $file in FileList('\\server\share,'.pdf') ? $file next
code:
Function FileList($folderName,optional $mask) $objDir = CreateObject("Scripting.FileSystemObject").GetFolder($folderName).Files if @error exit 1 endif ; usually folder not found For Each $objFile In $objDir $name=$objFile.name if ($mask and instr($name,$mask)) or not $mask $t=$t+'|'+$name endif Next $FileList=split(substr($t,2),'|') EndFunction
|
|
Top
|
|
|
|
#76558 - 2003-09-01 01:12 AM
Re: DirList with Owner of files
|
Richie19Rich77
Seasoned Scripter
   
Registered: 2002-08-16
Posts: 624
Loc: London, England
|
Ok I have updated my script, this is so much better.
Using FSO.Files and FSO.SubFolders and then FileOwner to get ownership.
ProgressBar all working now, NO bugs found.
Works really fast.
; ********************************************************************************* ; * Script Name: Display Owner of Files & Folders * ; * Creator: Richard Farthing - Queen Elizabeth Hospital NHS Trust * ; * Date: 1/09/03 * ; * Requirments FileOwner Function, KiXforms v2.3.0 Beta 3, * ; * KiXtart 4.22 Beta 1 * ; *********************************************************************************
Break On ; Break On to allow user to break out
;********************************************************************************************************** ;Checking that KiXtart Forms DLL is Registered If NOT ReadValue("HKEY_CLASSES_ROOT\CLSID\{78F2E57A-21C9-467D-B20B-6836E9A36272}\InprocServer32", "ThreadingModel") = "Both" MessageBox("KiXtart Forms Register DLL Failed, Please contact the IMT Helpdesk on x6049", "Displays Owner of Files & Folders - KiXtart Forms DLL Register Failed", 0) GoTo End EndIf
;********************************************************************************************************** $KiX = "D:\KiX" ; Set the KiX verable Call $Kix+'\Functions\FileOwner().Kix' ; Calling the FileOwner() Function
;********************************************************************************************************** ;Type in the Drive Letters of the Shared Drive and the IMS Drive.
$FirstDrive = "C:\" $SecondDrive = "D:\" ;Leave as "" if you do not want a second drive.
;********************************************************************************************************** ;Create Object to KiXtart Form $FORM = CreateObject("Kixtart.Form")
;********************************************************************************************************** ;Main Form
$FORM.Caption = "Displays Owner of Files & Folders" $FORM.ScaleHeight = 240 $FORM.ScaleWidth = 405 $FORM.FontSize = 8 $FORM.Center
;********************************************************************************************************** ;Current Directory Label
$ListCurrentDir = $FORM.Label $ListCurrentDir.Left = 5 $ListCurrentDir.Top = 30 $ListCurrentDir.Width = 380 $ListCurrentDir.Height = 20 $ListCurrentDir.FontSize = 8 $ListCurrentDir.FONTNAME = "Arial" $ListCurrentDir.Enabled = 0
$lblCurrentDir = $FORM.Label("Current Folder: ") $lblCurrentDir.Left = 5 $lblCurrentDir.Top = 15 $lblCurrentDir.Width = 120 $lblCurrentDir.Height = 20 $lblCurrentDir.FontSize = 8 $lblCurrentDir.FONTNAME = "Arial" $lblCurrentDir.Enabled = 0
;********************************************************************************************************** ;ListView for OwnerList
$GetOwnerListBox = $FORM.Listview $GetOwnerListBox.Left = 5 $GetOwnerListBox.Top = 55 $GetOwnerListBox.Width = 395 $GetOwnerListBox.Height = 160 $GetOwnerListBox.FontSize = 8 $GetOwnerListBox.FONTNAME = "Arial" $GetOwnerListBox.View = 1 $GetOwnerListBox.SmallImageList = $Form.SmallImageList $GetOwnerListBox.OnDoubleClick = "ListView_DoubleClick()" $=$GetOwnerListBox.Columns.Add("Name",250) $=$GetOwnerListBox.Columns.Add("Owner",125) $FolderRoot = $FirstDrive
;********************************************************************************************************** ;Command Button for select Drive
If $SecondDrive $SelectDrive = $FORM.CommandButton $SelectDrive.Left = 278 $SelectDrive.Top = 7 $SelectDrive.Width = 115 $SelectDrive.Height = 20 $SelectDrive.FontSize = 8 $SelectDrive.FONTNAME = "Arial" $SelectDrive.Text = "Click to Browse "+$SecondDrive $SelectDrive.OnClick = "SelectDrive_Click()" EndIf
;********************************************************************************************************** ;ProgressBar for DirList
$ProgressBar = $FORM.ProgressBar() $ProgressBar.Width = 300 $ProgressBar.Height = 15 $ProgressBar.Left = 50 $ProgressBar.Top = 220 $ProgressBar.Style = 2 $ProgressBar.Minimum = 0 $ProgressBar.Enabled = 0
;********************************************************************************************************** ;Objects within Main Form
$FORM.Show ; Show Form
ListView() ; Call ListView Function
While $FORM.Visible $=Execute($FORM.DoEvents) Loop :End Exit 1
;*********************************************************************************************************** ;Call Functions & UDF's **** ;***********************************************************************************************************
;*********************************************************************************************************** ;ListView Function
Function ListView()
Enabled(0) ; Call Enabled Function $ListCurrentDir.Text = $FolderRoot ; Set Current Directory Label
$FSO = CreateObject("Scripting.FileSystemObject").GetFolder($FolderRoot) $ProgressBar.Maximum = $FSO.SubFolders.Count + $FSO.Files.Count ; Set the maximum value of the ProgressBar to count of the Files and Folders Array $=$GetOwnerListBox.Items.Add("..",47) ; Create Item for ".."
$x = 1 ;Folder Array For Each $FolderListArray In $FSO.SubFolders $ProgressBar.Value = $x ; Set Value of ProgressBar to $x $Owner = Split(FileOwner($FolderListArray),"\") ;Split Object into an Array using "\" $=$GetOwnerListBox.Items.Add($FolderListArray.Name+"\",1) ;Add FolderName Item into Listview $GetOwnerListBox.Items($x).SubItems(1).Text = $Owner[Ubound($Owner)] ; Add Owner Item into ListView $x = $x + 1 Next
;File Array For Each $FileListArray In $FSO.Files $ProgressBar.Value = $x $Owner = Split(FileOwner($FileListArray),"\") $=$GetOwnerListBox.Items.Add($FileListArray.Name,0) $GetOwnerListBox.Items($x).SubItems(1).Text = $Owner[Ubound($Owner)] $x = $x + 1 Next
Enabled(1) ; Call the Enabled Function
EndFunction
;*********************************************************************************************************** ;ListView Double Click Function
Function ListView_DoubleClick() For Each $Item In $GetOwnerListBox.SelectedItems $ItemName = $Item.Text If $ItemName = ".." ; If ItemName = ".." If NOT $FolderRoot = SubStr($FolderRoot,1,2)+'\' ; If $FolderRoot does NOT Contain the 1st 2 charcters of FolderRoot $FolderRootSplit = Split($FolderRoot,"\") ; Splits the FolderRoot into an Array on "\" charcter ReDim PRESERVE $FolderRootSplit[Ubound($FolderRootSplit) -2] ; ReDim the FolderRootSplit Array and cut off the last 2 segments of the array but kee p the data $FolderRoot = Join($FolderRootSplit,"\")+'\' ; Re join the array and use "\" as the joining character $GetOwnerListBox.Items.Clear ; Clear the ListView of all Items ListView() ; Call the ListView Function EndIf Else If NOT InStr($ItemName,"\") = 0 ; If "\" is NOT in Selected ItemName $FolderRoot = $FolderRoot+"$ItemName" ; Set FolderRoot $GetOwnerListBox.Items.Clear ; Clear the ListView of all Items ListView() ; Call the ListView Function EndIf EndIf Next
EndFunction
;*********************************************************************************************************** ;Set the FolderRoot Verable
Function SelectDrive_Click()
If SubStr($FolderRoot,1,3) = $FirstDrive $FolderRoot = $SecondDrive $SelectDrive.Text = "Click to Browse "+$FirstDrive Else $FolderRoot = $FirstDrive $SelectDrive.Text = "Click to Browse "+$SecondDrive EndIf
$GetOwnerListBox.Items.Clear ListView()
EndFunction
;*********************************************************************************************************** ; Set the Enabled Function
Function Enabled($Option) $ProgressBar.Value = 0 $GetOwnerListBox.Enabled = $Option
If $SelectDrive.Enabled = 0 OR $SelectDrive.Enabled = 1 $SelectDrive.Enabled = $Option EndIf
EndFunction
;***********************************************************************************************************
[ 01. September 2003, 13:56: Message edited by: Richard Farthing ]
|
|
Top
|
|
|
|
#76560 - 2003-09-01 01:49 AM
Re: DirList with Owner of files
|
Richie19Rich77
Seasoned Scripter
   
Registered: 2002-08-16
Posts: 624
Loc: London, England
|
?? sorry what have I done.
Someone answer me this simple thing.
Why can't I find the UBound of the following array.
code:
$FSO = CreateObject("Scripting.FileSystemObject").GetFolder($FolderRoot).Files
$ProgressBar.Maximum = Ubound($FSO) + 1
I can list each object within the $FSO, but it looks like it is not a true array.
??? any ideas [ 01. September 2003, 02:22: Message edited by: Richard Farthing ]
|
|
Top
|
|
|
|
#76564 - 2003-09-01 01:22 PM
Re: DirList with Owner of files
|
Richie19Rich77
Seasoned Scripter
   
Registered: 2002-08-16
Posts: 624
Loc: London, England
|
Thanks works like a dream.
code:
$ProgressBar.Maximum = $FSO.SubFolders.Count + $FSO.Files.Count
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 675 anonymous users online.
|
|
|