![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | File Extension I have a script that removes files with specific file extension and the script works fine. Here is the script: strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") strFolderName = "C:\Test" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.CreateTextFile("C:\Scripts\Test.txt") Set colSubfolders = objWMIService.ExecQuery _ ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _ & "Where AssocClass = Win32_Subdirectory " _ & "ResultRole = PartComponent") Set colFiles = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name='" & strFolderName & "'} Where " _ & "ResultClass = CIM_DataFile") For Each objFile in colFiles If objFile.Extension = "txt" Or objFile.Extension = "doc" Then objTextFile.WriteLine objFile.FileName WScript.Echo objFile.FileName & objFile.Extension End If Next For Each objFolder in colSubfolders GetSubFolders strFolderName Next Sub GetSubFolders(strFolderName) Set colSubfolders2 = objWMIService.ExecQuery _ ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _ & "Where AssocClass = Win32_Subdirectory " _ & "ResultRole = PartComponent") For Each objFolder2 in colSubfolders2 strFolderName = objFolder2.Name Set colFiles = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name='" & strFolderName & "'} Where " _ & "ResultClass = CIM_DataFile") For Each objFile in colFiles If objFile.Extension = "txt" Or objFile.Extension = "doc" Then objTextFile.WriteLine strFolderName & "\" & objFile.FileName & "." & objFile.Extension & " has been deleted on " & Date() & " " & Time WScript.Echo strFolderName & "\" & objFile.FileName & "." & objFile.Extension & " has been deleted on " & Date() & " " & Time 'will delete file objFile.delete End If Next GetSubFolders strFolderName Next End Sub One question in the following code If objFile.Extension = "txt" Or objFile.Extension = "doc" Then ... For each extension do I have to use objFile.Extension = "doc" or objFile.Extension = "RW" or objFile.Extension = "rwx" and so on.... - Is there an easier way to just list the file extensions without repeating objFile.Extension about 5 times Thanks |
My System Specs![]() |
| | #2 (permalink) |
| | Re: File Extension "freddy" <freddy@xxxxxx> wrote in message news:5E4C509E-4E56-44F7-9706-3BB19CA2DBBC@xxxxxx Quote: >I have a script that removes files with specific file extension and the > script works fine. Here is the script: > > One question in the following code > If objFile.Extension = "txt" Or objFile.Extension = "doc" Then ... > For each extension do I have to use objFile.Extension = "doc" or > objFile.Extension = "RW" or objFile.Extension = "rwx" and so on.... - Is > there an easier way to just list the file extensions without repeating > objFile.Extension about 5 times Select Case LCase(objFile.Extension) Case "txt","doc","rw","rwx" 'Do Something Case Else 'Do Something Else End Select |
My System Specs![]() |
| | #3 (permalink) |
| | Re: File Extension "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message news:%23i$vZbRCJHA.3484@xxxxxx Quote: > "freddy" <freddy@xxxxxx> wrote in message > news:5E4C509E-4E56-44F7-9706-3BB19CA2DBBC@xxxxxx Quote: >>I have a script that removes files with specific file extension and the >> script works fine. Here is the script: >> >> One question in the following code >> If objFile.Extension = "txt" Or objFile.Extension = "doc" Then ... >> For each extension do I have to use objFile.Extension = "doc" or >> objFile.Extension = "RW" or objFile.Extension = "rwx" and so on.... - Is >> there an easier way to just list the file extensions without repeating >> objFile.Extension about 5 times > You could use 'Select Case': > > Select Case LCase(objFile.Extension) > Case "txt","doc","rw","rwx" > 'Do Something > Case Else > 'Do Something Else > End Select > > to a variable. For example strExt = LCase(objFile.Extension) If (strExt = "txt") Or (strExt = "doc") Then In this situation, the Select Case is best (and it is easier to read). -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| File Extension | Software | |||
| File extension | Vista General | |||
| .pps file extension | Vista General | |||
| How do you change file name extension in File/Dir Explorer? | Vista General | |||
| File Extension | PowerShell | |||