Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!larry!polyslo!vlsi3b15!vax1.cc.lehigh.edu!lusgr From: lusgr@vax1.cc.lehigh.edu (Steve Roseman) Newsgroups: comp.unix.aix Subject: Re: Need subroutine to return full file path name Message-ID: <10076.25e512f9@vax1.cc.lehigh.edu> Date: 23 Feb 90 15:39:53 GMT References: <10071.25e01a55@vax1.cc.lehigh.edu> Organization: Lehigh University Lines: 35 In article <10071.25e01a55@vax1.cc.lehigh.edu>, lusgr@vax1.cc.lehigh.edu (Steve Roseman) writes: > I need to find out the full path name of a file from a full or partial > name entered by the user, so other users can access the file (assuming > proper permissions, etc.) > > For example, a user currently in /u/mydir/sub: > > input: test.c output: /u/mydir/sub/test.c > input: /u/frog output: /u/frog > input: ../filename output: /u/mydir/filename > > ... Thanks to the several respondents who had suggestions. Nothing, unfortunately, was workable, so I finally kludged up my own routine. 1. Separate the dir part from the file name (via strrchr). 2. If only a file name, append the name to the current directory. Done. 3. Else, chdir to the directory part, do a getcwd, and chdir back to the original place. That gives me a full directory, and I add in the file name. Voila. Tacky, but... The performance may not be the greatest (getcwd works by piping the output of a pwd command), and error checking lacking a bit, but it will not be used heavily, and it got me past a bothersome hurdle. Thanks again for the suggestions, Steve (Wow, 2 non-RIOS articles in a row...) ------------------------------------------------------------------------- Steve Roseman Lehigh University Computing Center LUSGR@VAX1.CC.Lehigh.EDU