Forum Migration Notice
We're transitioning to a more modern community platform by the end of this year. Learn about the upcoming changes and what to expect.
Rename file using date at the end of the string. My code is included.
nezzreth
✭
in RobotStudio
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;
PERS num nGoodCycles;
VAR String Date;
PERS num WeekDay;
PERS num Hour;
PERS num Minute;
PERS num Second;
VAR iodev logfile;
PROC rGoodCycleCount()
Incr nGoodCycles;
Date:=CDate();
WeekDay:=GetTime(\WDay);
Hour:=GetTime(\Hour);
Minute:=GetTime(\Min);
Second:=GetTime(\Sec);
rWriteGoodCycleDayShift;
RETURN;
ENDPROC
PROC rWriteGoodCycleDayShift()
Open "HOME:/" \File:= "17_ALLI_0192.txt", logfile\append;
Write logfile, "GOOD CYCLE"\nonewline;
Write logfile, "*"+Date\nonewline;
Write logfile, "*"\Num:=Hour\nonewline;
Write logfile, ":"\Num:=Minute\nonewline;
Write logfile, ":"\Num:=Second;
Close logfile;
RETURN;
ENDPROC
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
Tagged:
0
Comments
-
I'm open to making new directories or an adjacent method that accomplishes the goal.0
-
Hi
You already have a variable with the date so you can just concatenate that on the end of your new file name - as below:
RenameFile "Home:/17_ALLI_0192.txt","Home:/17_ALLI_0192_JOB_END.txt"+date;
Regards
Graeme
1 -
Thank you for the response Graeme!graemepaulin said:Hi
You already have a variable with the date so you can just concatenate that on the end of your new file name - as below:
RenameFile "Home:/17_ALLI_0192.txt","Home:/17_ALLI_0192_JOB_END.txt"+date;
Regards
Graeme
I used the code you provided and it didn't quite work as anticipated.
It only added +Date to the end.
-Rick
0 -
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 againRenameFile "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!0 -
Hello,
I am doing this same thing.
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?
Thanks in advance.
0 -
This is the code I've been using to write to a "*.txt" file in my HOME directory.
PERS num nGoodCycles;PERS num Hour;PERS num Minute;PERS num Second;PROC rGoodCycleCount()Incr nGoodCycles;Date:=CDate();WeekDay:=GetTime(\WDay);Hour:=GetTime(\Hour);Minute:=GetTime(\Min);Second:=GetTime(\Sec);rWriteGoodCycle;RETURN;ENDPROCPROC rWriteGoodCycle()Open "HOME:/" \File:= "17_BORG_3027.txt", logfile\append;Write logfile, "1"\nonewline;Write logfile, "\\t"+Date\nonewline;Write logfile, "\\t"\Num:=Hour\nonewline;Write logfile, ":"\Num:=Minute\nonewline;Write logfile, ":"\Num:=Second;Close logfile;RETURN;ENDPROC0 -
I also use this code in my system module. I trigger it with an event routine RESET:rSaveAndClearEventVAR String Date;VAR iodev logfile;VAR dir directory;VAR string filename;VAR string name;VAR num nNameLength;VAR num nStringLength;VAR string part;PROC rSaveAndClearEvent()rSearchDir "HOME:/TEMPDATA","rSaveAndClear";ENDPROCPROC rSearchDir(string dirname, string actionproc)IF IsFile(dirname \Directory) THENOpenDir directory, dirname;WHILE ReadDir(directory, filename) DO! .. and . is the parent and resp. this directoryIF filename <> ".." AND filename <> "." THENrSearchDir dirname+"/"+filename, actionproc;ENDIFENDWHILECloseDir directory;ELSE%actionproc% dirname;ENDIFERRORRAISE;ENDPROCPROC rSaveAndClear(string filename)IF FileSize(filename) > 1024 THENDate:=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;ENDIFRETURN;ENDPROCPost edited by nezzreth on0
Categories
- All Categories
- 5.6K RobotStudio
- 401 UpFeed
- 21 Tutorials
- 15 RobotApps
- 306 PowerPacs
- 407 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.9K Robot Controller
- 365 IRC5
- 84 OmniCore
- 8 RCS (Realistic Controller Simulation)
- 854 RAPID Programming
- 37 AppStudio
- 4 RobotStudio AR Viewer
- 19 Wizard Easy Programming
- 110 Collaborative Robots
- 5 Job listings
