Return all paths, recursively to deepest level

Sjoerd Op 't Land sjoerdoptland at mac.com
Sun Feb 24 04:56:00 EST 2002


Sivakatirswami wrote/ schreef:

> Aloha:
> 
> I think about 2 years ago Kevin or Richard  sent me a script that would
> return the full path for all folders and files, recursively down from the
> current working directory... but I can't seem to find that script... Also I
> can't seem to find the archives any more for the metacard card list serve...
> [snip]
I made something myself, have a look below. Your list would be possible
with:

answer folder "Choose dir to dig..."
if the result is "Cancel" the exit to top
put relPath(deepFiles(it),it) into field "tFiles"

Regards, / Groeten,
Sjoerd

------- SCRIPT -------
function deepFiles startDir
  set the cursor to busy
  if it is "Cancel" then exit to top
  set the directory to startDir
  local tFiles
  repeat for each line tFile in the files
    put startDir & "/" & tFile into line (the number of lines in tFiles + 1)
of tFiles
  end repeat
  repeat for each line tDir in line 2 to -1 of the directories
    put deepFiles(startDir & "/" & tDir) into line (the number of lines in
tFiles + 1) of tFiles
    set the directory to startDir
  end repeat
  return tFiles
end deepFiles

function relPath absFiles,absDir
  repeat for each line tFile in absFiles
    put oneRelPath(tFile,absDir) into line (the number of lines in relFiles
+ 1) of relFiles
  end repeat
  return relFiles
end relPath

function oneRelPath absFile,absDir
  set itemDel to "/"
  repeat forever
    if item 1 of absDir = item 1 of absFile then
      delete item 1 of absFile
      delete item 1 of absDir
    else
      put repeatString("../",the number of items in absDir) before absFile
      exit repeat
    end if
  end repeat
  return absFile
end oneRelPath

function repeatString rString,rTimes
  local repeatedString
  repeat for rTimes times
    put rString after repeatedString
  end repeat
  return repeatedString
end repeatString




More information about the Use-livecode mailing list