File Watcher - Allow or Disallow Renaming Files or Folder in VB.NET

Submitted by: 
Visitors have accessed this post 260 times.

This is a continuation of my other yutorial named File Watcher - Allow or Disallow Creating Files or Folder in VB.NET, but in this tutorial it will grant to rename or disallow renaming of files and folder using

Now, let's start this tutorial!

1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.

2. Next, add one button named ButtonBrowse for browsing the folder path, a button named Button1 that will allow renaming of files and folder, and a button named Button2 that will disallow renaming of files and folder. Insert a FileSystemWatcher1FileSystemWatcher as our main component in this tutorial and one textbox for displaying the file path of the folder. You must design your interface like this:


3. Now, we will do the coding.

First we will locate the folder that we will allow or disallow the files that contains it. We will use FolderBrowserDialog in the browse button.

  1. Private Sub ButtonBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBrowse.Click
  3. Dim fbd As New FolderBrowserDialog
  5. If fbd.ShowDialog() = Windows.Forms.DialogResult.OK Then
  6. TextBoxPath.Text = fbd.SelectedPath
  7. End If
  8. End Sub

Then we will check if the file/folder path is a folder or a file using the rename method of our file watcher.

  1. Private Sub FileSystemWatcher1_Renamed(ByVal sender As System.Object, ByVal e As System.IO.RenamedEventArgs) Handles FileSystemWatcher1.Renamed
  2. 'check if its folder or file
  3. If New FileInfo(e.FullPath).Extension = Nothing Then
  4. My.Computer.FileSystem.RenameDirectory(e.FullPath, e.OldName)
  5. Else
  6. My.Computer.FileSystem.RenameFile(e.FullPath, e.OldName)
  7. End If
  10. End Sub

To allow renaming of files and folder, we will put the EnableRaisingEvents to False in the file watcher for Button1.

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. FileSystemWatcher1.EnableRaisingEvents = False
  3. End Sub

Lastly, put this code below for disallowing of renaming the files or folder in the specific path in your Button2.

  1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  2. FileSystemWatcher1.EnableRaisingEvents = True
  3. FileSystemWatcher1.Path = TextBoxPath.Text
  4. FileSystemWatcher1.IncludeSubdirectories = True
  5. End Sub

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]

Add and Follow me on Facebook:

Visit and like my page on Facebook at:

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.