What is the easiest way to rename a file created by the Tablefile instruction. I only get "LastFileName" from the command, but not the current file name.
You should use a variable of type String as the LastFileName parameter of the TableFile instruction. That will return a complete file name including the location. You can rename the file afterwards using the FileRename instruction. Below is a program I made by modifying the example program for TableFile.
'Measurement Variables
Public Bat, RefTemp, Temp
'TableFile variables
Public OutStat As Boolean, LastFileName As String * 25
DataTable (Test,True,-1)
DataInterval (0,5,Min,10)
TableFile ("USR:Test",8,-1,0,60,Min,OutStat,LastFileName)
Sample (1,Bat,FP2)
Sample (1,Temp,FP2)
EndTable
BeginProg
SetStatus ("USRDriveSize",16384)
Scan (1,Sec,3,0)
Battery(Bat)
PanelTemp (RefTemp,250)
TCDiff (Temp,1,mV2_5C,1,TypeT,RefTemp,True ,0,250,1.0,0)
CallTable (Test)
'Monitor the OutStat variable,and if a new file has been stored
'rrename that file
If OutStat Then FileRename (LastFileName,"USR:NewFileName")
NextScan
EndProg
JDavis: Thanks for the answer. Unfortunately the "LastFileName" lacks one step behind, thus giving me the previous, but not the present file name.
Just an idea but say you did get the present file name, you wouldn't be able to rename it because by definition, it's still open & being written to ? Can you explain why you want it and we can maybe come up with a solution.
Right, but once the task is finished and the file is written I want to rename it. For this I need to know its file name.
Public Bat, RefTemp, Temp
'TableFile variables
Public OutStat As Boolean, LastFileName As String * 25
Dim lngCount As Long
DataTable (Test,True,-1)
DataInterval (0,1,Min,10)
TableFile ("USR:Test",8,-1,0,1,Min,OutStat,LastFileName)
Sample (1,Bat,FP2)
Sample (1,Temp,FP2)
EndTable
BeginProg
SetStatus ("USRDriveSize",16384)
Scan (1,Sec,3,0)
Battery(Bat)
PanelTemp (Temp,250)
' TCDiff (Temp,1,mV2_5C,1,TypeT,RefTemp,True ,0,250,1.0,0)
CallTable (Test)
'Monitor the OutStat variable,and if a new file has been stored
'rename that file
If OutStat Then
FileRename (LastFileName,"USR:NewFileName" & lngCount)
lngCount = lngCount + 1
EndIf
NextScan
EndProg
Slightly altered code from JDavis, LastFileName does as I expect - you can't keep renaming the test file NewFileName as there's already one on user drive but give it a unique name and it worked as expected. Is there something I'm missing here ?
Hi all,
If I want to generate file everydays (from midnight to midnight) and that these file have the date in string format YYYYMMDD, how to proceed :
I think I can use FileTime(LastFileName) to retrieve the timestamp and then format the date as I precised above. But how to code that in CRbasic, especially to retrieve the date in YYYYMMDD and used it in FileRename function.
I have it:
LastFileTime = Datatable.Timestamp(3,1)
SplitStr(timearray(),LastFileTime,"",6,0)
Desiredtime = timearray(3)&timearray(2)&timearray(1)&timearray(4)&timearray(5)
Newfilename = "CRD:Begin"+Desiredtime+".csv"
If Outstat Then
FileRename(LastFileName,Newfilename)
EndIf