Newsletters   Subscriptions  Forums  Store   Career  Media Kit  About Us  Contact  Search   Home 
fhg
Volume 5, Number 38 -- October 12, 2005

Absolute Versus Relative Paths


by 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')
Sponsored By
ADVANCED SYSTEMS CONCEPTS

SEQUEL can be used for virtually ALL data access functions on the iSeries.

A Windows-based user interface makes it easy to design queries and reports.

SEQUEL offers executive dashboards, drill-down data analysis and run-time prompts to deliver important iSeries data to managers and other non-technical users.

E-mail and FTP delivery let you deliver information to remote users and servers.

www.asc-iseries.com


Technical Editors: Howard Arner, Joe Hertvik, Ted Holt,
Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.


THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
iSeries DevCon 2005
DRV Technologies


Four Hundred Guru

BACK ISSUES

TABLE OF
CONTENTS
Absolute Versus Relative Paths

Get to Know Some Powerful CL Commands

Admin Alert: Reader Feedback on Limiting Users with *ALLOBJ Authority


The Four Hundred
The IBM Systems Agenda: iB(M)

Q&A with the Dynamic Duo for iSeries Marketing and Sales

p5 Power5+ Machines Preview Possible Future i5s

As I See It: The Dog Ate My Manners

Four Hundred Stuff
PowerTech Debuts ComplianceMonitor, Studies Security Practices

Saving RPG and the iSeries--Now Isn't That Profound?

Looksoftware Developing New Product for Publishing Web Services

Aldon Supports iASPs with Change Management System

Four Hundred Monitor


Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc. (formerly Midrange Server), 50 Park Terrace East, Suite 8F, New York, NY 10034
Privacy Statement