Showing results for 
Search instead for 
Did you mean: 

Cannot create file

Go to solution

I am trying to create a time-stamped folder, and then within the folder, create a file called "Report.txt".

See below snippet.

The time-stamped part is correct - no argue about this, because a folder is really created, i.e ..\20120927185155

However in the time-stamped folder, it is empty. Apparently "Report.txt" wasn't created, for some reason.

Please help.




0 Kudos
Message 1 of 8
Accepted by splee

You have a race condition between creating the folder and creating the file. There's nothing defining the execution order. Make sure the folder is created before trying to create the file. Also, use "build path" (just like you do for the directory) to create the file path instead of converting to a string and back.


Message 2 of 8

Oh yes.. cos it is random. Sometimes the file is created, sometimes not. Most of the time it is not created.

I will try to use a sequence.

I can use a constant instead of "enum"?

0 Kudos
Message 3 of 8

Instead of a sequence you could also use data flow (using the path output or the error cluster of create folder). Can be problematic though if there is an error in the create folder function.

What "enum" are you talking about? I don't see an enum in your snippet.


Message 4 of 8

The enum which is supposed to be used for the open/create/file..

0 Kudos
Message 5 of 8

Ah I see. Yes, that works. But I don't see why you would do that.

The constant value gets translated into the corresponding enum position, so as long as the enum does not change using an integer constant will work. I would recommend using an enum constant, this also makes the code easier to read.



0 Kudos
Message 6 of 8

Have you looked at the "Format Date/Time String" function?



Message 7 of 8

Omar beat me to it.  Your whole business with the clusters and building of strings and be reduced down to just a Format Time String and a couple of Build Paths.  Here's a much cleaner version of your VI.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 8