Re: GETTING FULL PATHS
- Posted by Jacques Deschenes <desja at QUEBECTEL.COM> Jan 29, 1997
- 1119 views
At 15:47 29-01-97 PST, you wrote: >---------------------- Information from the mail header ----------------------- >Sender: Euphoria Programming for MS-DOS <EUPHORIA at >MIAMIU.ACS.MUOHIO.EDU> >Poster: David Cuny <HW1.DCUNY at HW1.CAHWNET.GOV> >Subject: GETTING FULL PATHS >------------------------------------------------------------------------------- > >is there a simple way to convert a string to a full path in Euphoria? >for example, the user could type in: > > "..\foo\bar" > >i know that you can use dir() to determine (1) that the path is real, >and (2) that the path is either a directory or a file. but i need to >convert the string to a full path, such as: > > "c:\stuff\bletch\foo\bar\" > >i could parse the thing by hand, but it would be easier if there was >a function that would expand it automatically. any suggestions? > >thanks. > >-- david cuny > Hi! David, If I understood your question, this could be an answer. include file.e function FindLastChar(integer char, sequence target) -- search target for a character starting search from end of target integer l, pos sequence inverse inverse="" l = length(target) for i = 0 to l-1 do inverse = inverse & target[l-i] end for pos = find(char,inverse) if not pos then return 0 else return l - pos end if end function --FindLastChar() function ExpandPath(sequence DottedPath) -- expand dotted path to full path -- limitation: only good for one level of dotting.(i.e. parent dir) integer pos sequence Current, Parent pos = match("..",DottedPath) if pos != 1 then return DottedPath end if Current = current_dir() Parent = Current[1..FindLastChar('\\',Current)] return Parent & DottedPath[3..length(DottedPath)] end function --ExpandPath() constant DotDir="..\\foo\\bar" puts(1,ExpandPath(DotDir)) Jacques Deschenes Baie-Comeau, Quebec Canada desja at quebectel.com