How do it like “file_name070508.txt”

rainylsh

Member
i'm a learner.
for example
output to "file_name.txt"
how can i do:
filename as file_name070508.txt
without output to "file_name070508.txt"
date "070508" auto plus.
 

gaurab

New Member
hiee .. u can do it this way :




DEF VAR my-datetime as CHAR no-undo.
DEF VAR v-filename AS CHAR no-undo.
DEF VAR v-location AS CHAR no-undo.
DEF VAR v-fullpath AS CHAR no-undo.


ASSIGN my-datetime = string(NOW)
my-datetime = SUBSTRING(my-datetime,1,R-INDEX(my-datetime, " ") - 1 )
my-datetime = replace(my-datetime,"~\","/")
my-datetime = replace(my-datetime,"/","").


ASSIGN v-filename = "file_name" + my-datetime + ".txt"
v-location = "c:\temp\" /* location of your file to be created */
v-fullpath = v-location + v-filename.


OUTPUT TO VALUE(v-fullpath).

PUT " your file contents ".

OUTPUT CLOSE.



and that was easy :lol:


Gaurab Poudel
Javra Software
http://www.javra.com :D
 
That is a lot of syntax. Try this simpler method, using the Sportsdb apply to your needs:DEFINE STREAM stDoc .OUTPUT TO "c:\doc.txt".FOR EACH Customer NO-LOCK:DISPLAY CustNum.END.Hope this helps
 

doreynie

Member
I think that rainylsh wants to be able to open and close file, without having to "hard code" this filename. So put your filename into a variable and do this :

assign
cFileName = "expression...".

output to value(cFileName).
put unformatted ....... skip.
output close.
 

joey.jeremiah

ProgressTalk Moderator
Staff member
Hello Gaurab,

While it is a good, elegant piece of code it is possible and there may be cases where a file with the same, exact name already exists.

You could, maybe, add a counter to the file name, for example, file_name(2).txt.


Another long time and commonly used, especially, in progress own code and utils procedure for generating temp file names is adecomm/_tmpfile.p.

You may also want to create a procedure for deleting temp files (including the client temp files, those that are not in use or locked).

Code:
----------------------------------------------------------
File: _tmpfile.p

Description:
         Creates an available temp file name. The name is a complete
         name that includes the path.

Input Parameters: 
         
         user_chars:   Characters that can be used to distinguish a temp
                                 file from another temp file in the same
application.
                                 
         extension:    The file extension that is to be added to the file,
                                                including the "."
         
Output Parameters:
        
         name:         The name of the file

Author: D. Lee

Date Created: 1993
----------------------------------------------------------
 

tamhas

ProgressTalk.com Sponsor
I suspect that the motivation here isn't a temp file name, since using a date wouldn't be unique any time within the same day. Often, the reason for a time stamped file like this is archive. But, you are right that it would generally be safer to make the pattern NameYYMMDDHHMMSS or some such in order to make it unlikely to get duplicates ... unless, of course, then intention was to overwrite any prior version or one opened it to append to any prior version.
 

gaurab

New Member
Thnks Joey and Tamas ,

It will sure be safer to add time with the date as well but wher can i get the procedure " adecomm/_tmpfile.p " .

regards,


Gaurab Poudel
Javra Software
http://www.javra.com
 

joey.jeremiah

ProgressTalk Moderator
Staff member
its in the adecomm.pl procedure library. you can extract the procedure library files if you wanted or needed to.

take a look at the extractpl script in the %dlc%\src directory

but the procedure can be runned from the procedure library just like running a procedure in a directory.

for example -

Code:
define var cFileName as char no-undo.

run adecomm/_tmpfile.p ( "tmp", ".txt", output cFileName ).

message cFileName view-as alert-box.
 

rainylsh

Member
thanks everyone's reply.
I've resolve it.
just assign a variable equal date + filename
then output to value(variable)
 
Top