LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

write to file within project folder

Hello, I know its probably a silly question but im having trouble writing to a file within the project folder. By default it saves it inside the project folder but im trying to save it to another directory called Results. The following is an example of what im trying to do.

 

strcpy(path, "\Results\");
    sprintf (buf,"%lu.txt ", (time));
    strcat(path, buf); 
    file = OpenFile (path,VAL_WRITE_ONLY, VAL_OPEN_AS_IS, VAL_ASCII); /* Create and write to file.*/

 

 

This seems to always give me errors in opening the file. Thanks

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

If you're only using one backslash, then you're potentially inserting a carriage return into your path ("\r"), since backslash is an escape character.  If you want a literal backslash, you need to use two blackslashes, i.e.

strcpy(path, "\\Results\\");

 

Also, I would recommend using the full path.  You can get the project directory using GetProjectDir() and build your path out of that.  CVI maintains a currect active directory for your project for relative paths, which is usually the project directory - but the active directory can be changed by other parts of the project code so I wouldn't count on it.

 

 

0 Kudos
Message 2 of 3
(2,644 Views)

Yeah i just found that function and it works great! thank you

0 Kudos
Message 3 of 3
(2,641 Views)