|I got to thinking, you said that you got an error. It would be nice to know what it was. I can only think of two reason you would get an error one, the filename above was getting too long, which was fixed by splitting the name instead of using the basename function. Two you have a file in the directory that doesn't have the date in the first line. The following should help you identify any files that don't contain the date in the proper place, I added another If statement that checks where the date is supposed to be, if the date is there, it does what it's supposed to. If it's not there it tells you the name of the file.|
Dim objFSO, colFiles, objFile, Lines, strNewName
Dim strFilePath, strEpoch, obJYourFolder, strOldName
objYourFolder = "C:\Your\folder\path"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colFiles = objFSO.GetFolder(objYourFolder).Files
For Each objFile in colFiles
strFilePath = objFile.ParentFolder & "\"
strOldName = Split(objFile.Name, ".")(UBound(Split(objFile.Name, "."))-1)
Lines = Split(objFSO.OpenTextFile(objFile).ReadAll, vbNewLine)
If (Mid(Lines(0),70,1)) <> "" then
If (Mid(Lines(0),70,1)) < 2 then
strEpoch = "20" & Mid(Lines(0),70,6)
strEpoch = "19" & Mid(Lines(0),70,6)
strNewName = strFilePath & strEpoch & ".abcd.1234D." & strOldName &".txt"
If not (objFSO.FileExists(strNewName)) then
objFSO.MoveFile objFile, strNewName
Wscript.Echo objFile & " does not contain a date in the first line."