Results 1 to 4 of 4

Thread: (Resolved) Rename Files while working with them

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    (Resolved) Rename Files while working with them

    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:
    1. '
    2.     Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click
    3.         Dim dir As New DirectoryInfo("C:\KVCpdfs\")
    4.         Dim strFileName As String = Nothing
    5.         Dim strNewName As String = Nothing
    6.         For Each file As FileInfo In dir.GetFiles()
    7.  
    8.             strNewName = ReadFile(file.FullName).ToString & ".pdf"
    9.             My.Computer.FileSystem.RenameFile(file.FullName, strNewName)
    10.  
    11.         Next
    12.     End Sub
    Last edited by BukHix; Sep 27th, 2009 at 09:59 PM. Reason: Resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width