ProblemI have image files that are RAW data and have the extension .NEF Whatever edits I make to these files are stored in what is called a sidecar file with the extension .xmpGiven there are many photos and the photo numbering in the camera can only go up to 9999, there is a possibility that I may get duplicate filenames in the same folder over time.ObjectiveGiven the image files and the sidecar files must have the same base name to remain associated, I'd like to append the date the photo was taken to the base name for both files. The original date can be found within the .xmp file on a line beginning with a specific string.I want to find all image files that have a sidecar fileGet the image date from within the sidecar fileRename both the image file and sidecar file with the date appended at the end of the base nameCodeI'm pretty sure I'm not importing any namespace except System.IO, so this should all be the .NET way, not any VB6.Option Explicit OnOption Strict OnOption Infer OnOption Compare TextImports System.IOModule PhotoRename    Sub Main()        Const DIR_PATH As String = C:\Temp\        Const IMAGE_EXTENSION As String = .NEF        Const SIDECAR_EXTENSION As String = .xmp        GetFilesInDirectory(DIR_PATH, IMAGE_EXTENSION, SIDECAR_EXTENSION)    End Sub    Private Sub GetFilesInDirectory(ByVal path As String, ByVal photoExtension As String, ByVal sidecarExtension As String)        Const EXTENSION_LENGTH As Integer = 4        Dim arrayOfFiles() As String = Directory.GetFiles(path, * & photoExtension)        Dim baseName As String        Dim photoFileName As String        Dim sidecarFileName As String        Dim originalDate As String        For arrayIndex As Integer = 0 To arrayOfFiles.Length - 1            photoFileName = arrayOfFiles(arrayIndex)            baseName = photoFileName.Substring(0, photoFileName.Length - EXTENSION_LENGTH)            sidecarFileName = baseName & sidecarExtension            If File.Exists(sidecarFileName) Then                originalDate = GetFileDate(sidecarFileName)                RenamePhotoFiles(baseName, originalDate, photoExtension, sidecarExtension)            End If        Next    End Sub    Private Function GetFileDate(ByVal sidecarFile As String) As String        Const LINE_START As String =    exif:DateTimeOriginal=        Const DATE_STRING_LENGTH As Integer = 10        Const CHAR_TO_REMOVE As String = -        Dim lines = File.ReadAllLines(sidecarFile)        Dim targetData As String = Nothing        For i As Integer = 0 To lines.Length - 1            If lines(i).StartsWith(LINE_START) Then                targetData = lines(i)                Exit For            End If        Next        targetData = targetData.Substring(LINE_START.Length + 1, DATE_STRING_LENGTH)        GetFileDate = targetData.Replace(CHAR_TO_REMOVE, )    End Function    Private Sub RenamePhotoFiles(ByVal oldName As String, ByVal fileDate As String, ByVal photoExtension As String, ByVal sidecarExtension As String)        Const FILE_EXTENDER As String = _        Dim newName As String = oldName & FILE_EXTENDER & fileDate        File.Move(oldName & photoExtension, newName & photoExtension)        File.Move(oldName & sidecarExtension, newName & sidecarExtension)    End SubEnd Module
Read date from a file and rename two files using the date
beginner;datetime;file;file system;vb.net
Important changeI would suggest you look at the Path class. A lot of your logic is about manipulating filename and this class does it all for you.Less important changeDepending on how big the file is, doing File.ReadAllLines might take more memory than needed. Reading one line at a time would be better.GetFilesInDirectory function name isn't true. It also renames the file.You could use a bit of error checking. For example, what happen if the string exif:DateTimeOriginal= can't be found in the file. What if there's no xmp file to the nef file.