1. wanted, code to get path from either filename or path\filename

i want a procedure to take any of these data sequences: c:\test\t*.*
                                                          \test\
                                                          t*

and change it to this:  c:\test\

eg: path = t*.*
    p = pathonly(path)
    puts(1,p)

which should print c:\test

new topic     » topic index » view message » categorize

2. Re: wanted, code to get path from either filename or path\filename

--------------D2F509E7DA0

Al,

I am not sure if this is exactly what you are looking for, but the
following takes a path/file spec and returns drive, path, file and
extension.

Dave

--------------D2F509E7DA0
Content-Disposition: inline; filename="PSPLIT.E"

global constant -- elements of returned sequence
  PSplit_DRIVE = 1,
  PSplit_DIRECTORY = 2,
  PSplit_FILENAME = 3,
  PSplit_EXTENSION = 4

global function PSplit(sequence Path)
-- Split a full path name to Drive, Directory, FileName and Extension

  atom Drive
  sequence Directory, FileName, Extension, ReturnValue

  atom Pos, Len
  sequence CurDir

  CurDir = current_dir()
  Pos = find(':',Path)
  if Pos > 0 then
    Drive = Path[Pos-1]
    Path = Path[Pos+1..length(Path)]
  else
    Drive = CurDir[1]
  end if

  Len = length(Path)
  Directory = ""
  for ix = Len to 1 by -1 do
    if compare(Path[ix],'\\') = 0 then
      Directory = Path[1..ix-1]
      Path = Path[ix+1..length(Path)]
      exit
    end if
    if compare(Path[ix], ':') = 0 then
      Directory = CurDir[3..length(CurDir)]
      exit
    end if
  end for
  if compare(Directory, "") = 0 then
    Directory = CurDir[3..length(CurDir)]
  end if

  Len = length(Path)
  FileName = ""
  Extension = ""
  for ix = Len to 1 by -1 do
    if compare(Path[ix], '.') = 0 then
      FileName = Path[1..ix-1]
      Extension = Path[ix+1..length(Path)]
      exit
    end if
  end for
  ReturnValue = {Drive, Directory, FileName, Extension}
  return ReturnValue
end function

--------------D2F509E7DA0--

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu