Check if String is a file or a folder VB.NET
<p>How do you check if a <code>String</code> value is a folder or a file? I'm using <code>FileSystemWatcher</code> to check for the changes in a file or a folder then I'm storing it in a <code>List(Of String)</code> with this code:</p>

<pre><code>Private Sub logrename(ByVal source As Object, ByVal e As System.IO.RenamedEventArgs)
    oldfldrnme.Add(e.OldName)
    newfldrnme.Add(e.Name)
End Sub
</code></pre>

<p>Using this code:</p>

<pre><code>Dim dest As String = Label6.Text

    For i = 0 To oldfldrnme.Count - 1 And newfldrnme.Count - 1
        Dim attri As FileAttribute = File.GetAttributes(i)
        If ((attri And FileAttribute.Directory) = FileAttribute.Directory) Then
            Microsoft.VisualBasic.FileIO.FileSystem.RenameDirectory(dest &amp; "\" &amp; oldfldrnme(i), newfldrnme(i))
        Else
            Microsoft.VisualBasic.FileIO.FileSystem.RenameFile(dest &amp; "\" &amp; oldfldrnme(i), newfldrnme(i))
        End If
    Next
</code></pre>

<p><code>FileNotFound Exception</code> throws, with this line <code>Visual Studio 2010\Projects\File Sync2\File Sync\bin\Debug\0'.</code></p>

<p>but with this code:</p>

<pre><code>For i = 0 To oldfldrnme.Count - 1 And newfldrnme.Count - 1
        Dim ex As String = Path.HasExtension(i)
        If ex = False Then
            Microsoft.VisualBasic.FileIO.FileSystem.RenameDirectory(dest &amp; "\" &amp; oldfldrnme(i), newfldrnme(i))
        Else
            Microsoft.VisualBasic.FileIO.FileSystem.RenameFile(dest &amp; "\" &amp; oldfldrnme(i), newfldrnme(i))
        End If
    Next
</code></pre>

<p>work with directories, but with files it tells that it's a directory, throwing <code>DirectoryNotFoundException</code> with this line <code>Could not find directory 'D:\Test2\New Text Document.txt'.</code></p>