"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
>
> Or, to avoid repeatedly retrieving a property value I often assign the value
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
--