![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Dumb question of the day I have no experience with VB scripting, so of course I was asked to write one.... Here's the question. Is there any VB code out there that is available for public use that would scan directories, and return information such as full path, extension, owner, file size, etc out there that I could use??? I signed up for a class on VBscripting, but they have postponed it twice so far this year, and my deadline is coming up soon. This is probably the easiest thing to do, and if it was C or Pascal (showing my age) it would be easy, but we don't have those compilers available at work.... Thanks for any help, and not laughing too hard... ;-) When you come to a fork in the road, take it. - Yogi Berra *** Sent via Developersdex http://www.developersdex.com *** |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Dumb question of the day "Dan Payne" <grumpyoldb@xxxxxx> wrote in message news:uwb9ULR6JHA.1092@xxxxxx Quote: >I have no experience with VB scripting, so of course I was asked to > write one.... > Here's the question. > Is there any VB code out there that is available for public use that > would scan directories, and return information such as full path, > extension, owner, file size, etc out there that I could use??? I signed > up for a class on VBscripting, but they have postponed it twice so far > this year, and my deadline is coming up soon. This is probably the > easiest thing to do, and if it was C or Pascal (showing my age) it would > be easy, but we don't have those compilers available at work.... > > Thanks for any help, and not laughing too hard... ;-) > > When you come to a fork in the road, take it. - Yogi Berra > > *** Sent via Developersdex http://www.developersdex.com *** No doubt with a proper requirements specification a solution could be easily constructed using DIR and CACLS and a few processing tricks. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Dumb question of the day "billious" <billious_1954@xxxxxx> wrote in message news:4a2e7cb7$0$32371$5a62ac22@xxxxxx-qv1-newsreader-01.iinet.net.au... Quote: > > "Dan Payne" <grumpyoldb@xxxxxx> wrote in message > news:uwb9ULR6JHA.1092@xxxxxx Quote: >>I have no experience with VB scripting, so of course I was asked to >> write one.... >> Here's the question. >> Is there any VB code out there that is available for public use that >> would scan directories, and return information such as full path, >> extension, owner, file size, etc out there that I could use??? I signed >> up for a class on VBscripting, but they have postponed it twice so far >> this year, and my deadline is coming up soon. This is probably the >> easiest thing to do, and if it was C or Pascal (showing my age) it would >> be easy, but we don't have those compilers available at work.... >> >> Thanks for any help, and not laughing too hard... ;-) >> >> When you come to a fork in the road, take it. - Yogi Berra >> >> *** Sent via Developersdex http://www.developersdex.com *** > Try alt.msdos.batch.nt. > > No doubt with a proper requirements specification a solution could be > easily constructed using DIR and CACLS and a few processing tricks. > http://www.microsoft.com/technet/scr....mspx?mfr=true. Sorry I can't verify that today. Just change the path you want to scan. Dim arrHeaders(35) Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.NameSpace("C:\scratch") For i = 0 To 34 arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i) Next For Each strFileName In objFolder.Items For i = 0 To 34 Wscript.Echo i & vbTab & arrHeaders(i) & ": " & objFolder.GetDetailsOf(strFileName, i) Next Next |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Dumb question of the day On Jun 9, 11:01*am, "LJB" <postmaster@[127.0.0.1]> wrote: Quote: > "billious" <billious_1...@xxxxxx> wrote in message > > news:4a2e7cb7$0$32371$5a62ac22@xxxxxx-qv1-newsreader-01.iinet.net.au... > > > > > > > Quote: > > "Dan Payne" <grumpyo...@xxxxxx> wrote in message > >news:uwb9ULR6JHA.1092@xxxxxx Quote: > >>I have no experience with VB scripting, so of course I was asked to > >> write one.... > >> Here's the question. > >> Is there any VB code out there that is available for public use that > >> would scan directories, and return information such as full path, > >> extension, owner, file size, etc out there that I could use??? *I signed > >> up for a class on VBscripting, but they have postponed it twice so far > >> this year, and my deadline is coming up soon. *This is probably the > >> easiest thing to do, and if it was C or Pascal (showing my age) it would > >> be easy, but we don't have those compilers available at work.... Quote: Quote: > >> Thanks for any help, and not laughing too hard... *;-) Quote: Quote: > >> When you come to a fork in the road, take it. - Yogi Berra Quote: Quote: > >> *** Sent via Developersdexhttp://www.developersdex.com*** Quote: > > Try alt.msdos.batch.nt. Quote: > > No doubt with a proper requirements specification a solution could be > > easily constructed using DIR and CACLS and a few processing tricks. > I think I got this fromhttp://www.microsoft.com/technet/scriptcenter/guide/sas_fil_lunl.mspx.... > Sorry I can't verify that today. Just change the path you want to scan. > > Dim arrHeaders(35) > > Set objShell = CreateObject("Shell.Application") > > Set objFolder = objShell.NameSpace("C:\scratch") > > For i = 0 To 34 > * *arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i) > Next > > For Each strFileName In objFolder.Items > * *For i = 0 To 34 > * * * Wscript.Echo i & vbTab & arrHeaders(i) & ": " & > objFolder.GetDetailsOf(strFileName, i) > * *Next > Next- Hide quoted text - > > - Show quoted text - #<--- Start Script ---------> $a = Get-Date -format g $row = 2 $xl = New-Object -c excel.application $xl.visible = $True $wb = $xl.workbooks.add() $sh = $wb.sheets.item(1) $sh.Range("A1:T1").Font.Bold = $true $sh.Range("A:A").Font.Bold = $True $sh.Cells.Item(1, 1) = "Computer Name" $sh.Cells.Item(1, 2) = "Date Run" + $a $sh.Cells.Item(1, 3) = "FullName" $sh.Cells.Item(1, 4) = "Length" $sh.Cells.Item(1, 5) = "Owner" $sh.Cells.Item(1, 6) = "Extension" $sh.Cells.Item(1, 7) = "LastAccessTime" $sh.Cells.Item(1, 8) = "CreationTime" $sh.Cells.Item(1, 9) = "Group Access" # you will need a list of computers, one computer name per line $computerlist = Get-Content 'c:\scripts\Servers.txt' foreach ($srv in $computerlist) { $sh.Cells.Item($row, 1) = $srv $response = Get-WmiObject -query "Select * From Win32_PingStatus Where Address = '$srv'" if( ($response -eq $null) -or ($response.StatusCode -ne 0)) { $sh.Cells.Item($row, 2).Font.ColorIndex = 3 $sh.Cells.Item($row, 2) = "Does Not Ping" $row++ } else { if ($response.TimeToLive -le 64) { $sh.Cells.Item($row, 2).Font.ColorIndex = 5 $sh.Cells.Item($row, 2) = "probably is a Unix host" $row++ } Else { # Change the path and the extension. If you want all files, remove the -include *.??? Get-ChildItem -path c:\scripts\ps1 -recurse -include *.ps1 -ea continue | foreach { $file = New-Object -TypeName System.Management.Automation.PSObject Add-Member -InputObject $file -MemberType NoteProperty -Name "FullName" -Value $_.Fullname Add-Member -InputObject $file -MemberType NoteProperty -Name "LastAccessTime" -Value $_.LastAccessTime Add-Member -InputObject $file -MemberType NoteProperty -Name "LastWriteTime" -Value $_.LastWriteTime $acl = Get-Acl -Path $_.FullName Add-Member -InputObject $file -MemberType NoteProperty -Name "Owner" -Value $acl.Owner Add-Member -InputObject $file -MemberType NoteProperty -Name "AccessToString" -Value $acl.AccessToString Add-Member -InputObject $file -MemberType NoteProperty -Name "Group" -Value $acl.Group $sh.Cells.Item($row, 3) = $_.FullName $sh.Cells.Item($row, 4) = $_.Length $sh.Cells.Item($row, 5) = $acl.Owner $sh.Cells.Item($row, 6) = $_.Extension $sh.Cells.Item($row, 7) = $_.LastAccessTime $sh.Cells.Item($row, 8) = $_.CreationTime $sh.Cells.Item($row, 9) = $acl.Group $sh.Cells.EntireColumn.AutoFit() $row++ } } } } $wb.SaveAs("C:\temp\find_files.xls") # close and release resources $wb.close($false) $xl.quit() spps -n excel #---- End Script --------------> |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Dumb question of the day "Dan Payne" <grumpyoldb@xxxxxx> wrote in message news:uwb9ULR6JHA.1092@xxxxxx Quote: >I have no experience with VB scripting, so of course I was asked to > write one.... > Here's the question. > Is there any VB code out there that is available for public use that > would scan directories, and return information such as full path, > extension, owner, file size, etc out there that I could use??? I signed > up for a class on VBscripting, but they have postponed it twice so far > this year, and my deadline is coming up soon. This is probably the > easiest thing to do, and if it was C or Pascal (showing my age) it would > be easy, but we don't have those compilers available at work.... > > Thanks for any help, and not laughing too hard... ;-) Note that Shell.Application folders are a completely different beast from File System folders. Shell.Application folders represent the folder windows that you see on your screen. Note that the columns displayed in a folder window are specific to that folder. Most folders have a standard set of columns, some have different specific sets, and a few have to include all the columns of the others -- the recycle bin, for instance. Windows Search windows and the Temporary Internet Files folders have some specialized columns, such as 'In Folder', and URL. You will probably want the main program to call a recursable function/subroutine to recurse through all folder levels from your starting folder. Option Explicit Dim oShellApp, oShFlder, oShFldrItem Set oShellApp = CreateObject("Shell.Application") 'Can access just about any folder window that ' you can see on your screen. Set oShFlder = oShellApp.NameSpace("C:\scratch") ' or ... Const RECYCLE_BIN = &hA& Set oShFlder = oShellApp.Namespace(RECYCLE_BIN) 'or even a WXP file search window with a few ' more lines of code.... For Each oShFldrItem In oShFlder.Items WScript.Echo ListDic(GetColumnValues(oShFldrItem)) WScript.Echo Next WScript.Echo "Done" Function ListDic(oDic) Dim sMsg, Key, sCRLF For Each Key In odic.Keys sMsg = sMsg & sCRLF & Key & ":" & vbTab & oDic(Key) sCRLF = vbCrLf Next 'Key ListDic = sMsg End Function 'ListDic(oDic) Function GetColumnNames(oShellFolder) 'Returns an dictionary where keys are column names ' and items are column numbers (zero based). Dim oDic, i, sDetail Set oDic = CreateObject("Scripting.Dictionary") oDic.CompareMode = vbTextCompare 'Iterate possible columns by numeric index 'I'm just guessing as to the legal range of ' column numbers For i = -128 To 127 sDetail = oShellFolder.GetDetailsOf(Empty, i) If Len(sDetail) > 0 Then oDic(sDetail) = i End If Next Set GetColumnNames = oDic End Function 'GetColumnNames(oShellFolder) Function GetColumnValues(oShellFolderItem) 'Returns an dictionary where keys are column names ' and items are the text value for that item in that ' column, followed by a tab character and the column ' number (zero based). 'For example, the first column is typically the item ' name, so the first entry in the dictionary would ' be key "Name", item "itemNameVbTab0" 'Some folders, such as the recycle bin) can hold a ' wide variety of files, and ' have a long list of columns to handle that variety. ' Individual files seldom have values for all of ' those columns. Dim oDic, sDetail, oDicNames, sName, oShFldr Set oDic = CreateObject("Scripting.Dictionary") oDic.CompareMode = vbTextCompare Set oShFldr = oShellFolderItem.Parent Set oDicNames = GetColumnNames(oShFldr) 'Iterate possible columns by numeric index, putting ' only those with a value for the column into the ' dictionary. For Each sName In oDicNames sDetail = oShFldr.GetDetailsOf _ (oShellFolderItem, oDicNames(sName)) If Len(sDetail) > 0 Then oDic(sName) = sDetail & vbTab & oDicNames(sName) End If Next Set GetColumnValues = oDic End Function 'GetColumnValues(oShellFolderItem) -Paul Randall |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Dumb question of the day "Paul Randall" <paulr901@xxxxxx> wrote in message news:eu3%23n2h6JHA.4864@xxxxxx Quote: > > Here is a script that should help get you going. 1) Run my script under CScript or you will be OK-ing hundreds of message boxes. 2) Shell.Application FolderItems will refer to files and folders. Some files have a sort of duality -- they can be considered files or folders. ..CAB and .Zip files are treated as folders, and you can get at their first level of contents as FolderItems. To go further into the internal file/folder structure, you would have to extract the contents of the CAB/Zip file and then create a namespace object for the extracted items. 3) Although not completely up to date, this link is about the best reference I've found for scripting the Shell.Application object: http://msdn.microsoft.com/en-us/library/bb776890.aspx -Paul Randall |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Dumb question of the day On Jun 10, 7:04*pm, "Paul Randall" <paulr...@xxxxxx> wrote: Quote: > "Paul Randall" <paulr...@xxxxxx> wrote in message > > news:eu3%23n2h6JHA.4864@xxxxxx > > > Quote: > > Here is a script that should help get you going. > I forgot to say a few things. > > 1) Run my script under CScript or you will be OK-ing hundreds of message > boxes. > 2) Shell.Application FolderItems will refer to files and folders. *Some > files have a sort of duality -- they can be considered files or folders. > .CAB and .Zip files are treated as folders, and you can get at their first > level of contents as FolderItems. *To go further into the internal > file/folder structure, you would have to extract the contents of the CAB/Zip > file and then create a namespace object for the extracted items. > 3) Although not completely up to date, this link is about the best reference > I've found for scripting the Shell.Application object:http://msdn.microsoft.com/en-us/library/bb776890.aspx > > -Paul Randall Get-ChildItem -path c:\scripts\ps1 To this: Get-ChildItem -path \\$srv\c$ |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| WPF - Possible Dumb Question | .NET General | |||
| Probably a dumb question but... | .NET General | |||
| Dumb Question 3 | Vista General | |||
| Is this a dumb question? | Vista General | |||
| Dumb question...RC2 | Vista installation & setup | |||