[COLOR=green][FONT=Times New Roman]'=============================================[/FONT][/COLOR]
[COLOR=green][FONT=Times New Roman]'References:[/FONT][/COLOR]
[COLOR=green][FONT=Times New Roman]'Visual Basic For Applications[/FONT][/COLOR]
[COLOR=green][FONT=Times New Roman]'Microsoft Access 9.0 Object Library[/FONT][/COLOR]
[COLOR=green][FONT=Times New Roman]'Microsoft DAO 3.6 Object Library[/FONT][/COLOR]
[COLOR=green][FONT=Times New Roman]'Microsoft Scripting Runtime[/FONT][/COLOR]
[COLOR=green][FONT=Times New Roman]'=============================================[/FONT][/COLOR]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] filenum [COLOR=blue]As[/COLOR] Integer [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] Count [COLOR=blue]As[/COLOR] Long [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] tmp [COLOR=blue]As[/COLOR] String [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] rst [COLOR=blue]As[/COLOR] DAO.Recordset [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] DB [COLOR=blue]As[/COLOR] Database [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] FS [COLOR=blue]As[/COLOR] FileSystemObject [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] Folder [COLOR=blue]As[/COLOR] Folder [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] subFolder [COLOR=blue]As[/COLOR] Folder [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] File [COLOR=blue]As[/COLOR] File [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] [COLOR=red]TextFilePath[/COLOR] [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] dtmDate [COLOR=blue]As[/COLOR] Date [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] dtmFileDate [COLOR=blue]As[/COLOR] Date [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] TextFileDate [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] NameOfFile [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] FileNameWithExt [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] strTemp [COLOR=blue]As[/COLOR] String [/FONT]
[FONT=Times New Roman] [COLOR=blue]Dim[/COLOR] FileLoc [COLOR=blue]As[/COLOR] String [/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] [COLOR=blue]Const[/COLOR] ForReading = 1 [/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] [COLOR=blue]Set[/COLOR] DB = CurrentDb [/FONT]
[FONT=Times New Roman] [COLOR=blue]Set[/COLOR] FS = CreateObject("Scripting.FileSystemObject") [/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] dtmDate = Date [/FONT]
[FONT=Times New Roman] [COLOR=red]TextFilePath[/COLOR] = "[COLOR=red]B[/COLOR]:\" [COLOR=green]'Set the text file path here [the location where text files are be stored][/COLOR][/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] [COLOR=blue]If Not[/COLOR] FS.FolderExists([COLOR=red]TextFilePath[/COLOR]) [COLOR=blue]Then[/COLOR] [COLOR=green]'If we can't read the text file folder, stop running[/COLOR][/FONT]
[FONT=Times New Roman] MsgBox "Folder Doesn't Exist", , "Reading Text Files"[/FONT]
[FONT=Times New Roman] [COLOR=blue]End[/COLOR][/FONT]
[FONT=Times New Roman] [COLOR=blue]End If[/COLOR][/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] [COLOR=blue]Set[/COLOR] Folder = FS.GetFolder([COLOR=red]TextFilePath[/COLOR]) [COLOR=green]'Open the text file folders[/COLOR][/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] [COLOR=blue]For Each[/COLOR] subFolder In Folder.SubFolders [COLOR=green]'Loops through the Folders looking for SubFolders[/COLOR][/FONT]
[FONT=Times New Roman] [COLOR=blue]For Each[/COLOR] File In subFolder.Files [COLOR=green]'Loops through Subfolders looking for Files[/COLOR][/FONT]
[FONT=Times New Roman] [COLOR=blue]If[/COLOR] Right(File.Name, 4) = ".[COLOR=red]txt[/COLOR]" [COLOR=blue]Then[/COLOR] [COLOR=green]'If the file found has a ".[/COLOR][COLOR=red]txt[/COLOR][COLOR=green]" extension then[/COLOR][/FONT]
[FONT=Times New Roman] FileNameWithExt = Mid$(File.Name, InStrRev(File.Name, "\") + 1)[/FONT]
[FONT=Times New Roman] strTemp = Mid$(File.Name, InStrRev(File.Name, "\") + 1) [/FONT]
[FONT=Times New Roman] NameOfFile = Left$(strTemp, InStrRev(strTemp, ".") - 1) [/FONT]
[FONT=Times New Roman] subFilePath = Left$(subFolder, InStrRev(subFolder, "\")) [/FONT]
[FONT=Times New Roman] SubFolderName = Mid$(subFolder, InStr(3, subFolder, "\")) [/FONT]
[FONT=Times New Roman] FileLoc = subFolder & "\" & File.Name [/FONT]
[FONT=Times New Roman] [/FONT]
[FONT=Times New Roman] [COLOR=blue]If[/COLOR] Dir("[COLOR=red]G:\Scan - Verify\eFlow\BackupProdRegOnprdfs01[/COLOR]" & SubFolderName, vbDirectory) = "" [COLOR=blue]Then[/COLOR] [/FONT]
[FONT=Times New Roman] MkDir ("[COLOR=red]G:\Scan - Verify\eFlow\BackupProdRegOnprdfs01[/COLOR]" & SubFolderName) [/FONT]
[FONT=Times New Roman] FS.CopyFile subFolder & "\" & FileNameWithExt, "[COLOR=red]G:\Scan - Verify\eFlow\BackupProdRegOnprdfs01[/COLOR]" & SubFolderName & "\" & NameOfFile & "_" & Format(Date, "ddmmyy") & ".[COLOR=red]txt[/COLOR]" [/FONT]
[FONT=Times New Roman] [COLOR=blue]Else [/COLOR][/FONT]
[FONT=Times New Roman] FS.CopyFile subFolder & "\" & FileNameWithExt, "G:\Scan - Verify\eFlow\BackupProdRegOnprdfs01" & SubFolderName & "\" & NameOfFile & "_" & Format(Date, "ddmmyy") & ".[COLOR=red]txt[/COLOR]" [/FONT]
[FONT=Times New Roman] [COLOR=blue]End If[/COLOR][/FONT]
[FONT=Times New Roman] [COLOR=blue]Next[/COLOR][/FONT]
[FONT=Times New Roman] [COLOR=blue]Next[/COLOR][/FONT]