Renaming a file in the IFS directory

20 pts.
Tags:
Application development
AS/400
CLP
DataCenter
PC/Windows Connectivity
I am receiving a file daily in an IFS directory, I manually copy the file to a library using the CPYFRMSTMF command. I want to automate the process so that it will be done every day at a specific time. The challenge is that the file name in the IFS directory is different every day, for example it is ABC121206 today and ABC121306 tomorrow and the CPYFRMSTMF cannot take a generic value such as ABC*. Is there a process or API that would rename the file to a generic name in the IFS so that the CPYFRMSTMF command would use that name every days? Thanks

Answer Wiki

Thanks. We'll let you know when a new response is added.

If the file name contains a date. Create a variable with the constant (i.e. ABCxxxxxx). You can do it one of two ways (chgvar &filename (‘ABC’ || &date)) or (chgvar substr(&filename,4,6) &date). Use the variable (&filename) in you copy statement.

=============================================

If you have Qshell installed, try experimenting with something like this:<pre>
crtdtaara MYLS *char 32
qsh cmd(‘ls | datarea -w -l MYLS’)
dspdtaara MYLS</pre>Note that the “pipe” character between the ls and datarea utilities will need to be the appropriate pipe character for your system. Right now, my emulator sessions require using “!”.

There are far better ways of doing this, but you need something simple for now. What I coded is simply to give you an example to see if it can be adapted. You ought to be able to copy/paste those commands onto a command line (watching the “pipe”.)

The code creates a basic *char(32) data area in the current library — pick a library you prefer, set the size you need. The STRQSH commands then list (ls) the current directory to standard out, which is piped into the datarea utility, which writes (-w) lines to the MYLS data area found in the library list (-l). You can then display the data area to see what’s there. In a CL program, you’d use RTVDTAARA rather than DSPDTAARA of course.

If you try variations of ls, you can choose the path that you want to list and set a pattern to select which files to list. If there’s only and always just a single file, then you probably won’t have to worry much.

It’s not very sophisticated. I didn’t think you needed anything but the basics. It should be easy enough to adapt for various purposes.

Tom

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Imazing
    If you need the process to be more forgiving you can create a list of the file names in the IFS folder and populate a physical file with the results. Then run a program to use CPYFRMSTMF for each filename in your physical file. Here is some sample CL code to create the physical file with the list of filenames in the IFS the reason for filelist2 is this PF has the field name in it. CLRPFM FILE(mylib/FILELIST) QSH CMD('(LS /IFSfoldername>/QSYS.LIB/mylib.LIB/FILELIST.FILE/FILELIST.MBR)') CPYF FROMFILE(mylib/FILELIST) TOFILE(mylib/FILELIST2) MBROPT(*REPLACE) FMTOPT(*NOCHK)
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following