LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating File Based on TimeStr and DateStr

Hello

 

I am trying to set up an automatic new log file opening sequence in my program using DateStr and TimeStr as follows:

 

char gLogPath[MAX_PATHNAME_LEN];

int handleLogFile;

 

Fmt(gLogPath,"C:\\RunData\\MTB_RUN%s%s.txt",DateStr(),TimeStr());  

RemoveFileIfExists (gLogPath);
handleLogFile = OpenFile (gLogPath, VAL_WRITE_ONLY, VAL_TRUNCATE, VAL_ASCII); // Create it

The program errors out saying that there is a "bad file handle". If I had only a single '\' in my file path then I receive a warning saying that there are bad characters \R and \M in my file path, so I converted these two to '\\'. Can someone please suggest where I am going wrong here?

 

Thanks

Ajit

 

0 Kudos
Message 1 of 2
(3,576 Views)

The cause of the error can be in the result of DateStr () and TimStr (), depending on date and time separators as defind in control panel: as an example, my locale uses slashes as date separators and colons as time separators, both of them illegal inside a filename...

If this is your case, you could for example design a function that scans the string and substitutes those characters with hyphens or underscores.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(3,568 Views)