I am trying to change the file names of all the files in a directory based on content of the file. So I am opening the file, reading the content, storing the new file name in a variable and then trying to change the name of the file.
This is not working because when I start this loop I am opening the file and viewing it so it won't allow me to change while the file is in use. Should I store the old and new file names in an array and do the renames after the For Next Loop is complete?
VB Code:
' Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click Dim dir As New DirectoryInfo("C:\KVCpdfs\") Dim strFileName As String = Nothing Dim strNewName As String = Nothing For Each file As FileInfo In dir.GetFiles() strNewName = ReadFile(file.FullName).ToString & ".pdf" My.Computer.FileSystem.RenameFile(file.FullName, strNewName) Next End Sub




Reply With Quote