• 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
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    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

  • The Power11 Transistor Count Discrepancies Explained – Sort Of
  • Is Your IBM i HA/DR Actually Tested – Or Just Installed?
  • Big Blue Delivers IBM i Customer Requests In ACS Update
  • New DbToo SDK Hooks RPG And Db2 For i To External Services
  • IBM i PTF Guide, Volume 27, Number 33
  • Tool Aims To Streamline Git Integration For Old School IBM i Devs
  • IBM To Add Full System Replication And FlashCopy To PowerHA
  • Guru: Decoding Base64 ASCII
  • The Price Tweaking Continues For Power Systems
  • IBM i PTF Guide, Volume 27, Numbers 31 And 32

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