I’m currently writing timestamped data to a text file. Then, pulling the data from the text file for an excel spreadsheet. I would like to be able to use a RESET event routine to save that text file with a new name using the current date at the end of the name. Am I able to do this? rSaveAndClear is the proc I would like to be triggered by the event. Ideally, I copy/rename the current text file (17_ALLI_0192.txt), add the current date to the end (17_ALLI_0192_20170531.txt) and remove all data from the old one.
PERS num nGoodCycles;
VAR String Date;
PERS num WeekDay;
PERS num Hour;
PERS num Minute;
PERS num Second;
VAR iodev logfile;
PROC rSaveAndClear()
RenameFile “Home:/17_ALLI_0192.txt”, “Home:/17_ALLI_0192_JOB_END.txt”; <--------Can I add in the date during the rename???
Open “HOME:/” \File:= “17_ALLI_0192.txt”, logfile\write;
Write logfile, " ";
Close logfile;
RETURN;
ENDPROC
Graeme!
You used a word (concatenate) I hadn’t heard before.
After searching the manuals for this word I discovered what you were saying.
I changed my code in the following way:
PROC rSaveAndClear()
Date:=CDate();<-----I was missing this to request the date again
RenameFile “Home:/17_ALLI_0192.txt”, “Home:/17_ALLI_0192_”+Date+“.txt”;<—I had to change to this format to get the file to save correctly.
Open “HOME:/” \File:= “17_ALLI_0192.txt”, logfile\write;
Write logfile, " ";
Close logfile;
RETURN;
ENDPROC
Thank you very much for your response!
My life has just been made much easier!
and I haven’t been able to load or unload a “.txt”, “.Doc” or a “.Log” through my network connection. Is it possible to load or unload these files from the Home directory?
I also use this code in my system module. I trigger it with an event routine RESET:rSaveAndClearEvent
VAR String Date;
VAR iodev logfile;
VAR dir directory;
VAR string filename;
VAR string name;
VAR num nNameLength;
VAR num nStringLength;
VAR string part;
PROC rSearchDir(string dirname, string actionproc)
IF IsFile(dirname \Directory) THEN
OpenDir directory, dirname;
WHILE ReadDir(directory, filename) DO
! .. and . is the parent and resp. this directory
IF filename <> “..” AND filename <> “.” THEN
rSearchDir dirname+“/”+filename, actionproc;
ENDIF
ENDWHILE
CloseDir directory;
ELSE
%actionproc% dirname;
ENDIF
ERROR
RAISE;
ENDPROC
PROC rSaveAndClear(string filename)
IF FileSize(filename) > 1024 THEN
Date:=CDate();
nStringLength:=StrLen(filename);
nNameLength:=nStringLength-19;
part:=StrPart(filename,16,nNameLength);
RenameFile filename, “Home:/ERRORDATA/”+part+“_”+Date+“.txt”;
Open filename, logfile\write;
Write logfile, " ";
Close logfile;
ENDIF
RETURN;
ENDPROC