This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Add an incremental number to saved file.

I'm trying to add an incremental number to the file I'm saving in the Output_Multiple function because I have the same file running through

multiple outputs with the same file extention. I already have the integer x for the file loop, but don't know how to implement that into the sFile variable

to add the number when saving the file. The data1.dat file is feeding sOutdir and sOutExt.

Any help is appreciated.

Output_Multiple(string sOutput, string sOutDir, string sFile, string sOutExt) //string sExt,
 CAD.SpecifyOutputName.OK.Click()
 CAD.Output.OK.Click()
 CAD.Output.SaveAs.TextField.SetText(sOutDir+ sFile + sOutExt )//sOutExt
 CAD.Output.SaveAs.Save.Click()


testcase Output_Ard () appstate MyDefaultBaseState

 do

   string sTestDir = "BTest\Output_Ard\"
   string sOutDir = sPath+"output.files\"+sVerNum+"\"+sTestDir
   string sGoldDir = sPStart+sTestDir+"Gold\"

   string sOutput
   string sOutExt

   string sFileName

   // start script

   list of FILEINFO lfFiles
   lfFiles = SYS_GetDirContents(sPStart + sTestDir)   
   string sFile
   int x
   for x=1 to ListCount(lfFiles)

      sFile = lfFiles[x].sName
      string sExt
      sExt = Right(sFile, 4)
      if(sExt == ".ARD" || sExt == ".ard")

       do

           OpenDismissDialog(sPStart+sTestDir+sFile)
           //recording

           CAD.SetActive()

           HFILE hfile
           sFileName = (sPStart+sTestDir+"Data1.dat")
           hfile = FileOpen (sFileName, FM_READ)
           while (FileReadValue(hfile, sOutput))

                   FileReadValue(hfile,sOutExt)
                   //FileReadValue(hfile,sOutput)

                   Sleep(2)
                   Output_Multiple(sOutput, sOutDir, sFile, sOutExt) //run standard read from file
                   CloseFileDismissDialog()

except

   WriteIncomplete("Error-Output of {sOutDir + sFile}.cf2 Output failed")

  • Suggested Answer

    0  

    Hi

    Here is a basic example of adding the value of "x" into a file name:

        [ ] LIST OF FILEINFO lfFiles = SYS_GetDirContents("D:\Cases\RobertM")
        [ ] int fileCount = ListCount(lfFiles)
        [ ]
        [ ] String fileName, fileExtension
        [ ]
        [ ] integer x
        [-] for x =1 to fileCount
            [ ] //Print(lfFiles[x].sName)
            [-] if(!lfFiles[x].bIsDir)
                [ ] int extensionPos = StrPos(".", lfFiles[x].sName, TRUE)
                [ ] fileName = Left(lfFiles[x].sName, extensionPos-1)
                [ ] fileExtension = Right(lfFiles[x].sName, Len(lfFiles[x].sName)-extensionPos)
                [ ] Print("{fileName}{x}.{fileExtension}")//Insert value of x into fileName

    I hope that helps.

    Regards
    Robert

  • 0 in reply to   

    Thanks for the solution Robert. I searched for a solution, but couldn't find anything with all the pieces. This is a big help!

    JM