Just a tip for the day.
If you got a tab limited file and want to read it as a CSV file, using the file layout, use the below code snippet.
Local File &TABFILE, &CSVFILE;
Local string &FILE_NAME, &DATA, &NEWDATA;
&FILE_NAME = "Test.txt";
&TAB = Char(9);
&TABFILE = GetFile(&FILE_NAME, "r");
&FileName = &TABFILE.Name;
&POS = Find(".", &FileName);
&NEWFILE_NAME = Substring(&FileName, 1, &POS) | "dat";
&CSVFILE = GetFile(&NEWFILE_NAME, "N", %FilePath_Absolute);
If &TABFILE.IsOpen And
&CSVFILE.IsOpen Then
While &TABFILE.ReadLine(&DATA);
&NEWDATA = Substitute(&DATA, &TAB, ",");
&CSVFILE.WriteLine(&NEWDATA);
End-While;
&TABFILE.Close();
&CSVFILE.Close();
End-If;
Will be handy...
Or you can change your File Layout to use Tab Delimiter instead of comma.
ReplyDeleteDaniel,
ReplyDeleteSeems like that option is not there anymore.
Varun
Tab delimiter is available at least as of PT 8.53.08
ReplyDelete