HEELPBOOK - OBJFSO.DELETEFILE WITH WILDCARDS (VISUAL BASIC) ############################ Tipically, you will can use wildcards, in a VBScript, using the following notation: set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.DeleteFile(RootFolder & "*.txt") Where RootFolder will be the full path (computed or hardcoded) in which reside all the text files we want to delete. ########## ADVANCED SCENARIO Trying to build a script to go through some nested directories and delete any file with a specific extension. Example paths are: {root_path}\Folder1\{terminal_path}\somefile.fmi {root_path}\Folder2\{terminal_path}\someotherfile.fmi For about 25 folders. ############### SOLUTION This solution involves a directory structure of the following type: {root_path}\ {VARIABLE_PATHS} \{terminal_path}\{wildcard_files} So, we'll have to define an array that we'll contain all the {VARIABLE_PATHS}, so the subroutine EmptyFolders will delete any *.txt files founded during its recursive process, using the .DeleteFile method built on a simple string contatenation. Option Explicit Dim RootFolder,Folderpath Dim i Dim aFolderList() RootFolder = "{root_path}\" Folderpath = "\{terminal_path}\" FillFolderList EmptyFolders on error resume next Sub FillFolderList ReDim aFolderList(3) aFolderList(0) = "Folder1" aFolderList(1) = "Folder2" aFolderList(2) = "Folder3" end sub sub EmptyFolders() On Error Resume Next Dim objFSO set objFSO = CreateObject("Scripting.FileSystemObject") For i = 0 to UBOUND(aFolderList) - 1 objFSO.DeleteFile(RootFolder & aFolderList(i) & Folderpath & "*.txt") next end sub ############ ARTICLE INFO ############# Article Month: January Article Date: 24/01/2012 Permalink: http://heelpbook.altervista.org/2013/objfso-deletefile-with-wildcards-visual-basic/ Source: http://forums.aspfree.com/visual-basic-programming-38/objfso-deletefile-wildcards-103997.html Language: English View more articles on: http://www.heelpbook.net/ Follow us on Facebook: http://it-it.facebook.com/pages/HeelpBook/100790870008832 Follow us on Twitter: https://twitter.com/#!/HeelpBook Follow us on RSS Feed: http://feeds.feedburner.com/Heelpbook Follow us on Delicious: http://delicious.com/heelpbook Linkedin: http://it.linkedin.com/pub/stefano-maggi/27/73a/b20 Google+ : https://plus.google.com/116990277568167008289/posts