|
Each contribution is licensed to you under a License Agreement by its owner, not Microsoft. Microsoft does not guarantee the contribution or purport to grant rights to it.
|
Categories |
List Unique File Extensions Found in a Folder(Community)
Script Code
VBScript
'* Script name : UniqueFileExtensions.vbs
'* Created on : 1:01 PM 5/24/2008
'* Author : Kent Finkle
'* Purpose : Pick Out the Unique File Extensions Used in a Collection of Files
'* Link : /technet/scriptcenter/resources/qanda/may08/hey0509.mspx
'* Sample call : cscript UniqueFileExtensions.vbs "c:\scripts"
'* Notes : If no directory is passed in on the command line, the current
'* directory is used.
'* ================================================================================
Option Explicit
Const adVarChar = 200
Const MaxCharacters = 255
Dim strExtension
Dim objRecordSet
Dim objFso
Dim objFolder
Dim objFile
Dim strFolder
Set objRecordSet = CreateObject("ADOR.Recordset")
objRecordSet.Fields.Append "Extension", adVarChar, MaxCharacters
objRecordSet.Open
Set objFso = CreateObject("Scripting.FileSystemObject")
if Wscript.Arguments.Count = 0 then
strFolder = objFso.GetAbsolutePathName(".")
else
strFolder = Wscript.Arguments(0)
end if
if not objFso.FolderExists(strFolder) then
Wscript.Echo strFolder & " not found"
Wscript.Quit
end if
Set objFolder = objFso.GetFolder(strFolder)
For Each objFile In objFolder.Files
strExtension = objFso.GetExtensionName(objFile)
objRecordSet.Find "Extension = '" & strExtension & "' "
If (objRecordSet.BOF = True) OR (objRecordSet.EOF = True) Then
' Record not found
objRecordSet.AddNew
objRecordSet("Extension") = strExtension
objRecordSet.Update
Else
' skip
End If
objRecordSet.MoveFirst
Next
objRecordSet.Sort = "Extension"
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields.Item("Extension")
objRecordSet.MoveNext
Loop
Platforms
For online peer support, join
The Official Scripting Guys Forum!
To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
Disclaimer
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
Be the first to create a discussion.
|