How to create a varaible file name?

gdkve9gdkve9 Member Posts: 161
Hello everyone here in the forum..

I have to create a file whose name is variable which means for every time a processing report is run, a file with varaible name should get generated into a drive.

I have looked for variable file name in the forum but not able to get any clue here.

If is a static file name, for e.g., LSRETAIL.txt then we can use..

OutFileName Text 200
OutFile File

OutFileName := 'C:\LSRETAIL.txt';
OutFile.CREATE(OutFileName); //would create the file

But my problem is every time a new file should get generated in to some temp folder, the name being included with current date,current time,terminal no., transaction no. etc.

May be I am missing the basics here but will be very thankful if I get some solution for this.

Thanks in advance for all.
Dilip
Falling down is not a defeat..defeat is when you refuse to get up.

Comments

  • kapamaroukapamarou Member Posts: 1,152
    Last time I had to do something similar it was like this:

    reportTime := TIME;
    timeText := FORMAT(TODAY,0,'<Day>_<Month>_<Year4>');
    timeText += FORMAT(reportTime,0,'<Hours24,2>_<Minutes,2>_<Seconds,2>');

    fileName := fileName + timeText + '.txt';

    Is this close to what you need?
  • rdebathrdebath Member Posts: 383
    My favorite is to use a number series with the NoSeriesManagement codeunit.
      FileNo := NoSeriesManagement.GetNextNo(Setup."File No. Series", WORKDATE, TRUE);
    
  • gdkve9gdkve9 Member Posts: 161
    kapamarou wrote:
    fileName := fileName + timeText + '.txt';
    Now how could you will be able to create the file with the value stored in the "fileName" variable??

    Because if you assign a path like this

    OUtFileName := 'C:\fileName.txt';
    OutFile.Create(OutFileName); //would create the file name with fileName.txt but not with value stored in fileName varaible.

    Could you please mention the line of code for assigning a file name(which is stored in fileName varaible) along with the path(suppose if the file need to be created in C colon like C:\XXXXXXXXX.txt)

    Will be wiating for your valuable reply.

    Thanks.
    Dilip
    Falling down is not a defeat..defeat is when you refuse to get up.
  • kapamaroukapamarou Member Posts: 1,152
    OK.
    Declare the following text variables:

    pathName, fileName,fileStartName, timeText

    Declare myTime as time. Then Do:

    pathName := 'c:\outpoutfiles\'; <- Or any directory you want.

    fileStartName := 'LSRETAIL';

    myTime := TIME; <- Get the current time.
    timeText := FORMAT(TODAY,0,'<Day>_<Month>_<Year4>');
    timeText += FORMAT(reportTime,0,'<Hours24,2>_<Minutes,2>_<Seconds,2>'); <- These two lines give timeText the date and time.

    fileName := pathName + fileStartName + timeText + '.txt'; <- this concatenates the texts

    Then : OutFile.CREATE(fileName);

    Play around with this a bit to make it suit your needs...
  • gdkve9gdkve9 Member Posts: 161
    edited 2009-04-27
    kapamarou wrote:
    fileName := pathName + fileStartName + timeText + '.txt'; <- this concatenates the texts
    This worked fine.. =D> Thank U somuch Mr. kapamarou :D
    Dilip
    Falling down is not a defeat..defeat is when you refuse to get up.
  • kapamaroukapamarou Member Posts: 1,152
    You're welcome :D
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    gdkve9 wrote:
    I have to create a file whose name is variable which means for every time a processing report is run, a file with varaible name should get generated into a drive.
    Starting from NAV 4.x, there exists a CREATETEMPFILE (File) function:
    Use this function to create a temporary file. This enables you to save data of any format to a temporary file. This file has a unique name and will be stored in the temporary files folder.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
Sign In or Register to comment.