reading through multiple text files and putting content into new files
Hi Everyone,
I have a folder with multiple text files in it. I want to write a code that can read through these and organize the data into new files based on the values in the columns. So for example, to loop through and from 1,18 until it reaches 11,5 and take this data and put into new file. Then do that again continuously through all the txt files (the data is in separate folders so the first txt file may end at 7,10 so i would want to continue to the next file where it will pick up until it reaches 11,5).
I hope this makes sense.
Is this even possible?
Re: reading through multiple text files and putting content into new files
Quote:
Is this even possible?
yes i am sure it is
use DIR to loop through all files in folder
use OPEN to open text files
use SPLIT to put the text file into an array of the lines in file
as text files do not have columns reading the columns depends how the file is set up
more information would be required to give any more help
Re: reading through multiple text files and putting content into new files
Quote:
more information would be required to give any more help
I have the following code which converts all the .Htxt files i have in the folder to xlsx files. The files are output from a program that runs over night, which is the problem because the results for a run span over two days (the files automatically cutoff at midnight and then starts new file). So essentially the first part of every file needs to be at the end of the previous one (or the end of each needs to be at the beginning of the next. I am not sure how to reassign based on the beginning and end conditions. For example each run starts when column F has the value 1 and Column G has the value 18 and each ends when the values are 11 and 5.
Code:
Sub ConvertFiles()
Dim strFile As String
Dim strPath As String
With Application
.EnableEvents = False
.DisplayAlerts = False
.ScreenUpdating = False
End With
'Turn off events, alerts & screen updating
strPath = "C:\Users\kdunnigan\Documents\Lyo\Freeze Dryer log by day\"
strFile = Dir(strPath & "*.txt")
'Change the path as required
Do While strFile <> ""
Workbooks.Open Filename:=strPath & strFile, Format:=2
strFile = Mid(strFile, 1, Len(strFile) - 4) & ".xlsx"
ActiveWorkbook.SaveAs Filename:=strPath & strFile, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close True
strFile = Dir
Loop
'Opens the Workbook, set the file name, save in new format and close workbook
With Application
.EnableEvents = True
.DisplayAlerts = True
.ScreenUpdating = True
End With
'Turn on events, alerts & screen updating
End Sub
Re: reading through multiple text files and putting content into new files
Quote:
The files are output from a program that runs over night,
are these multiple files? or 2 files each night?
are the date times on the text file of help?
the text files could possibly be appended based on date time
Re: reading through multiple text files and putting content into new files
Quote:
are these multiple files? or 2 files each night?
are the date times on the text file of help?
the text files could possibly be appended based on date time
multiple files. Each file goes from 12:00am till 11:59 pm. then a new one starts. That's the issue. But the times the cycles start and end are different depending on ramp rate and stuff. But the values in the columns i mentioned always contain those values when it starts/ends. But the beginning end are often in two separate files if it runs overnight.
So I think the best would be to create a loop and assign values to new files using multiple conditions? I am just not sure exactly how to do this...