× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Ray,

> Is there an API that allows an IFS file to be moved from one location to
> another (program is in RPG)?  I should be able to use QCMDEXC to create
> a command ( MOV OBJ('/qdls/folder/file.txt') TODIR('/qdls/archive') ),
> but is there a better way to do this?

QCMDEXC should work.  The downside to QCMDEXC is that you may need to
escape the "from" and "to" filenames if they contain any special
characters, like for example, a single quote.  Most of the time that's not
a problem, but if the filename contains any data supplied by an external
source, like a user at the keyboard or a remote program, then you might
want to avoid QCMDEXC.

The IFS API to do a move is the Rename() API.   Actually, there's two
rename APIs, depending on the semantics required when the destination
object exists.  Qp0lRenameKeep() will produce an error if the destination
already exists, and Qp0lRenameUnlink() will delete the destination before
performing the rename.

If you think about it, you can see why "rename" and "move" are the same
thing.  You don't actually want to move the data that's in the file, you
just want to change the pathname that points to that data.  Therefore,
they're the same thing as long as the file is in the same filesystem.  (If
it's in a different filesystem, you must do a copy and then delete the
original, since in that case you DO want to move the file's data.)

Here's a sample of calling the rename() IFS API:

     H DFTACTGRP(*NO) BNDDIR('QC2LE')

     D rename          PR            10I 0 ExtProc('Qp0lRenameKeep')
     D   old                           *   Value options(*string)
     D   new                           *   Value options(*string)

     D ReportError     PR

     D Source          s            100A
     D Target          s            100A

     c                   eval      Source='/path/to/source/file.txt'
     c                   eval      Target='/path/to/destination/file.txt'

     c                   if        rename(%trimr(source):
     c                                    %trimr(target)) < 0
     c                   callp     ReportError
     c                   endif

     c                   eval      *inlr = *on


      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * ReportError():  Send an escape message explaining any errors
      *                 that occurred.
      *
      *  This function requires binding directory QC2LE in order
      *  to access the __errno() function.
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P ReportError     B
     D ReportError     PI

     D sys_errno       PR              *   ExtProc('__errno')
     D p_errno         s               *
     D errno           s             10I 0 based(p_errno)

     D QMHSNDPM        PR                  ExtPgm('QMHSNDPM')
     D   MessageID                    7A   Const
     D   QualMsgF                    20A   Const
     D   MsgData                      1A   Const
     D   MsgDtaLen                   10I 0 Const
     D   MsgType                     10A   Const
     D   CallStkEnt                  10A   Const
     D   CallStkCnt                  10I 0 Const
     D   MessageKey                   4A
     D   ErrorCode                 8192A   options(*varsize)

     D dsEC            DS
     D  BytesProv              1      4I 0 inz(0)
     D  BytesAvail             5      8I 0 inz(0)

     D MsgKey          S              4A
     D MsgNo           s              4P 0

     c                   eval      p_errno = sys_errno
     c                   eval      msgno = errno

     c                   callp     QMHSNDPM( 'CPE' + %editc(msgno:'X')
     c                                     : 'QCPFMSG   *LIBL'
     c                                     : ' ': 0: '*ESCAPE': '*': 3
     c                                     : MsgKey: dsEC)
     P                 E

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.