How do you check if a String
value is a folder or a file? I'm using FileSystemWatcher
to check for the changes in a file or a folder then I'm storing it in a List(Of String)
with this code:
Private Sub logrename(ByVal source As Object, ByVal e As System.IO.RenamedEventArgs)
oldfldrnme.Add(e.OldName)
newfldrnme.Add(e.Name)
End Sub
Using this 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 & "\" & oldfldrnme(i), newfldrnme(i))
Else
Microsoft.VisualBasic.FileIO.FileSystem.RenameFile(dest & "\" & oldfldrnme(i), newfldrnme(i))
End If
Next
FileNotFound Exception
throws, with this line Visual Studio 2010\Projects\File Sync2\File Sync\bin\Debug\0'.
but with this 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 & "\" & oldfldrnme(i), newfldrnme(i))
Else
Microsoft.VisualBasic.FileIO.FileSystem.RenameFile(dest & "\" & oldfldrnme(i), newfldrnme(i))
End If
Next
work with directories, but with files it tells that it's a directory, throwing DirectoryNotFoundException
with this line Could not find directory 'D:\Test2\New Text Document.txt'.