Hi Pat,
On 11/3/2010 2:30 PM, Pat Barber wrote:
How do you determine the home directory ?
for home directory, there are two APIs that I know of that will get it.
The Unix-type getpwnam() API and the QSYRUSRI API. You don't normally
need to get this in a CL program, however, you can just use the ~
special character. For example, I might do:
CPYTOIMPF FROMFILE(CUSTFILE) TOSTMF('~/custfile.csv')
The ~ character puts the file in my home directory -- no matter what my
current directory is.
How do you determine the current directory ?
In CL, I'd use the RTVCURDIR command. There's also the getpwd()
Unix-type API, which is easier to use from RPG.
But again, it's very rare to need to get this in an application -- you
can just use the special character, . (dot), to represent the current
directory, you don't usually need to know which directory it is. For
example:
CPYTOIMPF FROMFILE(CUSTFILE) TOSTMF('./custfile.csv')
In fact, if no directory is given, the current directory is the default,
so the following is equivalent to the preceding command:
CPYTOIMPF FROMFILE(CUSTFILE) TOSTMF('custfile.csv')
It's hard to envision the situation where you'd want to actually
retrieve the name of the current directory. It comes up occasionally
(for example, if you want to save it so you can return to it later) but
it's pretty rare.
The task at hand is to copy a monthly file from the Iseries
to the respected users mapped drives using cpytoimpf.
No idea what "mapped drives" means in this context. Mapping a drive is
a Windows concept, and we were talking about CL programming...
If you're talking about the spot in the IFS that the user is mapping a
drive _to_, then that could be _anywhere_, it depends on how your system
is configured.
It dawned on me that I will not neccessarily know who is
running the CLP that will be doing this and there fore will
not know how to construct the path correctly ex:
/home/patrick/detail_file.csv.
If you want to use the home directory, just do ~/detail_file.csv.
I not sure what you mean by a relative path vs absolute path.
Relative paths begin with your current directory. Absolute paths begin
at the root of the IFS.
For example, on my system, there's an (IBM supplied) directory named
/QIBM/ProdData/DeveloperTools/pase/AscTelnetSvr and in it are files
named unistd.h and termios.h. If I wanted to view those files, I might do:
DSPF '/QIBM/ProdData/DeveloperTools/pase/AscTelnetSvr/termios.h'
DSPF '/QIBM/ProdData/DeveloperTools/pase/AscTelnetSvr/unistd.h'
These are absolute paths because they begin with a / character. It
tells the IFS to start at the root of the IFS, and then proceed from
there... so it goes to the root, opens the QIBM directory, then from
QIBM, it opens ProdData, and from there opens DeveloperTools, then pase,
then AscTelnetSvr and finally termios.h. It starts at the root of the
IFS and goes forward through all of those directories to get to termios.h
It's an absolute path because it always starts at the "root" (the
beginning) of the IFS.
Using relative paths, I might save myself some typing:
CHGCURDIR '/QIBM/ProdData/DeveloperTools/pase/AscTelnetSvr'
DSPF 'termios.h'
DSPF 'unistd.h'
In this case, I change my current directory to the AscTelnetSvr
directory with the CHGCURDIR command... When I use the DSPF to access
the two files, it starts with whatever my current directory is and goes
forward from there. Since it doesn't start with a /, it's considered a
relative link... so it goes forward from whatever my current directory is.
I could've also done this (not sure why I would -- but just to
illustrate...)
CHGCURDIR '/QIBM/ProdData/DeveloperTools/pase'
DSPF 'AscTelnetSvr/termios.h'
DSPF 'AscTelnetSvr/unistd.h'
This results in the same thing as well, because the DSPF commands have
pathnames that don't start with a /, it goes forward from teh current
directory. In the curdir, it opens up AscTelnetSvr, and inside that, it
gets termios.h... IOW, it goes forward from my current dir.
I will also need to know if the path really exists in the IFS and
what to do if it does not.
I would submit that all users *should* have home directories. Creating
that directory should be part of the procedure when a new userid is
created. For existing users, I'd do a one-off program that creates their
home directories if they don't exist.
But if you really want to create it in the application (which might be
advisable if your software is to be distributed to other folks systems)
then by all means, retrieve the home directory and create it if it
doesn't exist.
But it doesn't really sound like you want to use a curdir -- it sounds
like you want to use the user's home dir, because maybe your system has
all of the home dirs set up as network shares?
What if folder patrick does not exist ?
CRTDIR creates a new directory.
Many of the IFS CL commands have aliases that make them more similar to
what they'd be on Unix/Windows. CRTDIR is OS/400-like, but MKDIR is an
alias. CHGCURDIR is OS/400-like, and CHDIR and CD are aliases, etc.
Also, if it's not already obvious... "home directories" are intended
to be like "My Documents" (on Windows). A user's personal space to
store whatever they're working on. Unix systems also tend to use them
for keepign track of per-user configuration files or settings.
"current directory" is mainly to save wear and tear on typing. It's
"the directory I'm currently in, so I don't have to retype it." Which
is why programs would be more apt to use absolute paths (since the user
doesn't have to type them) vs. users using relative paths.
Although the current directory _defaults_ to the home directory when the
user first signs on, that does _not_ mean they are the same thing (or
even closely related!) They have two different purposes. you may
already understand this -- but I've had too many frustrating days when
other people didn't, so I thought it was worth re-explaining.
As an Amazon Associate we earn from qualifying purchases.