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 vb.net.
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.
Private Sub ButtonBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBrowse.Click
Dim fbd As New FolderBrowserDialog
If fbd.ShowDialog() = Windows.Forms.DialogResult.OK Then
TextBoxPath.Text = fbd.SelectedPath
End If
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.
Private Sub FileSystemWatcher1_Renamed(ByVal sender As System.Object, ByVal e As System.IO.RenamedEventArgs) Handles FileSystemWatcher1.Renamed
'check if its folder or file
If New FileInfo(e.FullPath).Extension = Nothing Then
My.Computer.FileSystem.RenameDirectory(e.FullPath, e.OldName)
Else
My.Computer.FileSystem.RenameFile(e.FullPath, e.OldName)
End If
End Sub
To allow renaming of files and folder, we will put the EnableRaisingEvents to False in the file watcher for Button1.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FileSystemWatcher1.EnableRaisingEvents = False
End Sub
Lastly, put this code below for disallowing of renaming the files or folder in the specific path in your Button2.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
FileSystemWatcher1.EnableRaisingEvents = True
FileSystemWatcher1.Path = TextBoxPath.Text
FileSystemWatcher1.IncludeSubdirectories = True
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:
https://www.facebook.com/donzzsky
Visit and like my page on Facebook at:
https://www.facebook.com/BermzISware