How to Use Wildcards in Folder Names in Visual Basic

Written by james highland
  • Share
  • Tweet
  • Share
  • Email

Visual Basic is a robust computer language used in Windows and Microsoft applications to create complex interactive programs. The programming language can create stand-alone software, but it also allows algorithms to act on existing files and folders. The tool set of Visual Basic is extensive. Subroutines may be built to significantly alter the contents of a computer. Wild cards are a particularly versatile and powerful mechanism for creating programs that manipulate large sets of data without actually knowing the names of particular files. It is possible to use wild cards in folder names in Visual Basic.

Skill level:

Things you need

  • Visual Basic Editor

Show MoreHide


  1. 1

    Type the folder name and its full path as part of a regular Visual Basic function, such as \"Kill.\" Enclose the folder name and path in quotes.

  2. 2

    Replace part of the path with the wild card character, an asterisk (\"*\").

  3. 3

    Type a file extension after the wild card to process a batch of similar file types within the folder without regards to individual file names. For example: Kill \"c:\vbfiles\*.txt\". The wild card is used to operate on the folder name \"vbfiles\" to process all text documents it contains.

  1. 1

    Type a \"Dir()\" function to reference a folder name. This is a common Visual Basic function for specifying a particular directory or folder when calling outside files into the subroutine.

  2. 2

    Use the wild card character, an asterisk, in the folder name path to open the function to multiple files.

  3. 3

    Type a file extension after the wild card so the subroutine knows what to process in the folder. For example: Dir(\"C:\Windows\*.txt\").

Tips and warnings

  • Be careful with wild cards. They can act on more data than the programmer initially realises. Using a wild card, it is possible to involve an unlimited amount of data in the subroutine. This can have catastrophic consequences if the subroutine alters or deletes data. Additionally, the program may run slowly if the wild card has access to thousands of files, or folders of enormous size. While the wild card is a useful tool, it is also powerful and potentially dangerous if implemented without consideration for all possible scenarios.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.