• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Absolute Versus Relative Paths

    October 12, 2005 Ted Holt

    Faithful reader Bobby recently contacted me for help. He was having some trouble copying files between a library and the root file system. Helping him resolve his problem reminded me that the topic of addressing objects in the Integrated File System (IFS) is confusing and deserves to be written about from time to time.

    I’ll use a Copy to Import File (CPYTOIMPF) command to illustrate the type of problem that Bobby ran into. Pay attention to the TOSTMF parameter, which indicates a stream file (IFS file) into which the data is to be copied.

    The first command copies a database file into an IFS file called custinfo.csv, but where is that IFS file located? That is, which file system, or which directory, stores the stream file?

    CPYTOIMPF FROMFILE(MYLIB/MYFILE *FIRST) 
              TOSTMF(custinfo.csv)           
              STMFCODPAG(*PCASCII)           
              RCDDLM(*CRLF)
    

    In this example, the custinfo.csv file is created or overwritten in the job’s current directory. A job’s current directory is the directory that is assumed when no directory is specified. The current directory can be any of the following:

    • an IFS directory
    • a folder
    • a database file
    • a library

    Normally you’ll want to use an IFS directory for stream files. I’ve experimented with database files and haven’t found them too friendly for stream data.

    If you’re ever in doubt as to which directory is your current directory, use the Display Current Directory (DSPCURDIR) command. You can use the Change Current Directory (CHGCURDIR, CD, or CHDIR) command to use another directory instead.

    Assuming that the current directory in this example is /home/bobby, the command is interpreted as if the following had been keyed:

    CPYTOIMPF FROMFILE(MYLIB/MYFILE *FIRST) 
              TOSTMF('/home/bobby/custinfo.csv') 
              STMFCODPAG(*PCASCII)           
              RCDDLM(*CRLF)
    

    Here’s a second example. Notice that the stream file is placed in the “dot” directory.

    CPYTOIMPF FROMFILE(MYLIB/MYFILE *FIRST)
              TOSTMF('./custinfo.csv')      
              STMFCODPAG(*PCASCII)          
              RCDDLM(*CRLF)
    

    The “dot” notation is a short way of referring to the current directory. This example does the same as the first one.

    Let’s move to the third example. The stream file is placed into the “dot-dot” directory, which is the parent directory of the current directory.

    CPYTOIMPF FROMFILE(MYLIB/MYFILE *FIRST) 
              TOSTMF('../custinfo.csv')      
              STMFCODPAG(*PCASCII)           
              RCDDLM(*CRLF)
    

    If the current directory is /home/jsmith, custinfo.csv is created or overwritten in /home.

    Let’s look at one more shortcut. In this example, the stream file is in the tilde directory.

    CPYTOIMPF FROMFILE(MYLIB/MYFILE *FIRST)
              TOSTMF('~/custinfo.csv')      
              STMFCODPAG(*PCASCII)          
              RCDDLM(*CRLF)
    

    Dig around in the IFS all you like, but I don’t think you’ll find a directory named ~. The tilde character is shorthand for the user’s home directory, the directory that is assigned in a user’s user profile. Take a look at the HOMEDIR parameter of the Create User Profile (CRTUSRPRF) command.

    To this point, I have been illustrating relative addressing. Where a stream file is located is relative to the current directory or to the home directory. But you may also use absolute addressing, which means that you tell the system exactly which directory to use, no matter what the current and home directories may be. To indicate that you want absolute addressing, begin the stream file name with a slash character.

    In this example, the custinfo.csv file is created in directory /home/jsmith/data, which would be found in the root file system.

    CPYTOIMPF FROMFILE(MYLIB/MYFILE *FIRST)     
              TOSTMF('/home/jsmith/data/custinfo.csv') 
              STMFCODPAG(*PCASCII)               
              RCDDLM(*CRLF)
    


    Now, let’s return to Bobby’s problem. He was running a homegrown command–one that he had not written–that required two file parameters specified in IFS format.

    SOMECMD FROMSTMF('QSYS.LIB/MYLIB.LIB/MYFILE.FILE/MYFILE.MBR') +
       TOSTMF('home/bobby/mydata.dat')
    

    The data that is being copied is in member MYFILE in file MYLIB/MYFILE. The command is to copy the data to stream file mydata.dat in directory /home/bobby, which should exist in the root file system of the IFS. However, notice that neither stream file name begins with a slash, which indicates that the system should use relative addressing. If the current directory is /home/bobby, the system interprets the command like this:

    SOMECMD FROMSTMF('/home/bobby/QSYS.LIB/MYLIB.LIB/MYFILE.FILE/MYFILE.MBR')
     + TOSTMF('/home/bobby/home/bobby/mydata.dat')
    

    To fix the problem, Bobby only needed to add initial slashes to the file names.

    SOMECMD FROMSTMF('/QSYS.LIB/MYLIB.LIB/MYFILE.FILE/MYFILE.MBR') +
       TOSTMF('/home/bobby/mydata.dat')
    

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Maxava

    Migrate IBM i with Confidence

    Tired of costly and risky migrations? Maxava Migrate Live minimizes disruption with seamless transitions. Upgrading to Power10 or cloud hosted system, Maxava has you covered!

    Learn More

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Aldon Supports iASPs with Change Management System SEA and RevSoft End Partnership for OS/400 Utilities

    Leave a Reply Cancel reply

Volume 5, Number 38 -- October 12, 2005
THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
iSeries DevCon 2005
DRV Technologies

Table of Contents

  • Absolute Versus Relative Paths
  • Get to Know Some Powerful CL Commands
  • Admin Alert: Reader Feedback on Limiting Users with *ALLOBJ Authority

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle