locked
How to rename file programmatically using connectvity studio classes RRS feed

  • Question

  • void renameFile(AppDocument document)
    {
        AppFilename                  destinationFilename;
        AppFileName                  fileName                    = mProcessor.format().parmArguments().value(#StreamFilename);
        AppFileName                  OriginalfileName            = mProcessor.format().parmArguments().value(fileName);
        container                    fileNameCont                = filenamesplit(fileName);
        AppPath                      destinationPath,targetPath;
        CntConnection                mConnection;
        CntMessageInstance           theInstance                 = mProcessor.format().parmArguments().value(#Instance);

        ;

            try
            {
                super();

                theInstance=CntMessageInstance::find(theInstance.InstanceId,false);

                mConnection=CntConnection::find(theInstance.ConnectionId);

                destinationPath = mConnection.filePath(mConnection.FilePath);
                targetPath=mConnection.filePath(mConnection.FileDestinationPath);

                timeOriginal=time2str(timeNow(),3,1);
                timeFormatted=subStr(timeOriginal,0,2)+subStr(timeOriginal,4,2)+subStr(timeOriginal,7,2);
                destinationFilename="@LIQ1104"+date2Str(today(), 321,2, 0, 2, 0, 4)+timeFormatted+"."+"@LIQ1074";


                //As it uses Custom file name,manual steps required to rename the file.
                AppTools::RenameFile(filename, destinationPath+"\\"+destinationFilename);
                AppTools::CopyFile(destinationPath+"\\"+destinationFilename,targetPath+"\\"+destinationFilename);
                AppTools::deleteFile(destinationPath+"\\"+destinationFilename);


            }
            catch(Exception::Error)
            {
                AppTools::deleteFile(destinationPath+"\\"+OriginalfileName);
                this.writeToException(Exception::Error);
            }

    }


    Raghu Rama Raju.ch
    Thursday, August 12, 2010 12:42 AM

Answers