Create a file if not found

Cjandura58

New Member
Hi all,
I have written this code but I keep getting a message that the output file can not be found. I assumed incorrectly that progress would create the file for me. That is my problem, if the file does not exist what is the syntax to create the file?

Thanks in advance for your help.
Carrie


Def Stream strmHELPL.
Def Var file-out As char No-undo.
Def Var v-crlf As char Format "x(2)" No-undo.
v-crlf = Chr(13) + Chr(10).


If Search("C:\unidev50\HELdata" + String(Today) + ".txt") = ? Then
File-info:file-name = "HELdata" + String(TODAY) + ".txt".
file-out = File-info:file-name.

Def Var f-strTmp As char No-undo.
f-strTmp = "".
f-strTmp =


Blah Blah Blah---- data to write out


Output Stream strmHELPL To Value(file-out).
Put Stream strmHELPL UnFormatted f-strTmp v-crlf.
Output Stream strmHELPL Close.
 
The following will do it (dont know what you were trying to do with the Search() line)

p.s. the string(today) part will try to look in subdirs, because of the '/' in the date format. If these dirs dont exist, then this will cause you problems too. If you dont want this, then I suggest
Code:
replace(string(today),"/","").
If you do then i suggest
Code:
os-create-dir value(C:\unidev50\HELdata" + substring(String(Today),1,5))
    no-error.
before the output stream command.


Def Stream strmHELPL.
Def Var file-out As char No-undo.
Def Var v-crlf As char Format "x(2)" No-undo.
v-crlf = Chr(13) + Chr(10).

file-out = "C:\unidev50\HELdata" + String(Today) + ".txt".

Def Var f-strTmp As char No-undo.
f-strTmp = "".
f-strTmp =

Blah Blah Blah---- data to write out


Output Stream strmHELPL To Value(file-out).
Put Stream strmHELPL UnFormatted f-strTmp v-crlf.
Output Stream strmHELPL Close.

Originally posted by Cjandura58
Hi all,
I have written this code but I keep getting a message that the output file can not be found. I assumed incorrectly that progress would create the file for me. That is my problem, if the file does not exist what is the syntax to create the file?

Thanks in advance for your help.
Carrie


Def Stream strmHELPL.
Def Var file-out As char No-undo.
Def Var v-crlf As char Format "x(2)" No-undo.
v-crlf = Chr(13) + Chr(10).


If Search("C:\unidev50\HELdata" + String(Today) + ".txt") = ? Then
File-info:file-name = "HELdata" + String(TODAY) + ".txt".
file-out = File-info:file-name.

Def Var f-strTmp As char No-undo.
f-strTmp = "".
f-strTmp =


Blah Blah Blah---- data to write out


Output Stream strmHELPL To Value(file-out).
Put Stream strmHELPL UnFormatted f-strTmp v-crlf.
Output Stream strmHELPL Close.
 
Originally posted by bendaluz2
The following will do it (dont know what you were trying to do with the Search() line)

p.s. the string(today) part will try to look in subdirs, because of the '/' in the date format. If these dirs dont exist, then this will cause you problems too. If you dont want this, then I suggest
Code:
replace(string(today),"/","" ).
If you do then i suggest
Code:
os-create-dir value(C:\unidev50\HELdata" + substring(String(Today),1,5)) 
no-error.
before the output stream command.


Def Stream strmHELPL.
Def Var file-out As char No-undo.
Def Var v-crlf As char Format "x(2)" No-undo.
v-crlf = Chr(13) + Chr(10).

file-out = "C:\unidev50\HELdata" + String(Today) + ".txt".

Def Var f-strTmp As char No-undo.
f-strTmp = "".
f-strTmp =

Blah Blah Blah---- data to write out


Output Stream strmHELPL To Value(file-out).
Put Stream strmHELPL UnFormatted f-strTmp v-crlf.
Output Stream strmHELPL Close.

I had this same line in my code, however, the systems gives me an error message that the file does not exist. This is true but I want the code to create the file if it does not exist, that was the purpose of the search command.
Thanks.
 
Originally posted by bendaluz2
p.s. the string(today) part will try to look in subdirs, because of the '/' in the date format. If these dirs dont exist, then this will cause you problems too. If you dont want this, then I suggest
Code:
replace(string(today),"/","" ).

Alternatively:

file-out = "C:\unidev50\HELdata" + String(Today,'999999') + ".txt".

Will produce the date string without '/' characters.
 
This may be the same thing that others have said, but what the heck, I'll use different words... ;)

When you check for the file you're looking in C:\unidev50.
But when you assign the variable that is ultimately the file name, you leave off "C:'unidev50" and just assign it to be "HELdata" + String(Today) + ".txt" ). I don't know what the default path is in your system, but in MY system that would cause the file to be created somewhere other than C:\unidev50.

Could it be that simple? - don't we just wish!

Mark
 
Back
Top