rename all files?

daveofgv

Well-known member
Joined
Sep 17, 2008
Messages
218
Location
Dallas, TX
Programming Experience
1-3
Just wondering (needing now)

anyone have a quick solution to rename a group of files in a directory -

I have 100's of files in a directory that have a eight digit number with an underscore then a nine digit number.....

12345678_987654321.tif

All I need is to delete the 12345678_ from all the files (numbers will be different in front of the underscore)

Anyone have a quick solution?

Thanks
 
something like this maybe?

        Dim directoryLocation As String = "C:\yourDirectory\"
        Dim files = New IO.DirectoryInfo(directoryLocation).GetFiles()

        For Each file In files
            file.MoveTo(File.FullName.Replace("12345678_", ""))
        Next


you may want to add a check for a existing file in case the new file name already exists in the same directory...


or same thing but shorter code
        For Each file In New IO.DirectoryInfo("C:\yourdirectory\").GetFiles()
            file.MoveTo(file.FullName.Replace("12345678_", ""))
        Next
 
Last edited:
Back
Top