Trying to right a VBScript that gets rid of files from a directory

Asked By Clive Valentine
03-Nov-09 11:15 AM
Earn up to 0 extra points for answering this tough question.

Hi,

I've tried to right a script that delete files of a certain type using the wildcard and _AFP_AFPINFO.

I've done some searching on the web and have come up empty as everything I found was for an extension or a file of a certain age.

Here's my test code, not entirely sure where I've gone wrong but I hope someone can put me in the right direction as it's driving me mad.

Thanks In advance

T1b

Dim objFSO, objFolder, objFiles, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFolder = objFSO.GetFolder("C:\Test")
     Set colSubfolders = objFolder.Subfolders
  Set objFiles = objFolder.Files
   For Each objFile in objFiles
          If UCase(left(objFile.Name,6)) = "*_AFP_*" Then objFile.Delete, True
       Next
     Set objFiles = Nothing
   Set objFolder = Nothing
 Set objFSO = Nothing

 

  Use the Percentage Symbol.

[)ia6l0 iii replied to Clive Valentine
03-Nov-09 12:16 PM
The Condtion would never evaluate to true , because the substring returned by the left(objFile.Name,6) would never be equal to "*_AFP_*" (without quotes). I believe you did that because you needed the wildcard. 
 
I believe you need to use the percentage symbol when you do a search based on wildcard. Like:
"%AFP%"

You can put a breakpoint if you are using this in Visual Studio or do a Write call to figure out what the substring returns.

  Or I think..

web mavin replied to Clive Valentine
03-Nov-09 12:56 PM

you could also try "InStr" function that would search for the string in your filename.

Something like:-

iPositionIndex = Instr(objFile.Name, "_AFP_")

Create New Account