• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

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

biomon

Giggle Architect
B Rep
0
0
0
Rep
0
B Vouches
0
0
0
Vouches
0
Posts
47
Likes
78
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
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:

filewatcherrename.png


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

  2. Dim

    fbd As

    New

    FolderBrowserDialog

  3. If

    fbd.

    ShowDialog

    (

    )

    =

    Windows.

    Forms

    .

    DialogResult

    .

    OK

    Then
  4. TextBoxPath.

    Text

    =

    fbd.

    SelectedPath
  5. End

    If
  6. 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


  8. 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: https://www.facebook.com/donzzsky

Visit and like my page on Facebook at: https://www.facebook.com/BermzISware


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,501

352,162

352,176

Top