Get a List of Files

Ken Ray kray at sonsothunder.com
Tue Aug 27 16:01:01 EDT 2002


I wrote a quick little "directorywalker" stack that does this, and reports
back whether it is a file (optionally along with its type) or a folder, and
(optionally) indents the hierarchy. It was for Windows files only (so
there's no Mac type/creator checking), but here's the script:

  -- Card controls: [X] Show Hierarchy, [X] Show Type, [popup menu
"Delimiters" - had "Spaces (2)", "Spaces (4)" or "Tabs" as choices
  -- Field 1 holds the result

global gHierList,gMainFolder,gBaseLevels

on mouseUp
  put "" into gHierList
  answer folder "Pick a folder you want to walk:"
  if it = "" then exit mouseUp
  set the itemDel to "/"
  put it into gMainFolder
  put the number of items of gMainFolder into gBaseLevels
  directoryWalk gMainFolder,(the hilite of btn "ShowHierarchy"),(the
selectedText of btn "Delimiters"),(the hilite of btn "ShowType")
  put gHierList into field 1
end mouseUp

on directoryWalk whatFolder,showHier,pDel,showType
  set the itemDel to "/"
  if "(2)" is in pDel then put 2 into numSpcs
  else put 4 into numSpcs
  put "                                        " into spcPad
  set the directory to whatFolder
  if showHier then
    put ((the number of items of whatFolder)) - gBaseLevels into numLevels
    if pDel <> "tabs" then
      do "put format(" & quote & "%" & (numLevels*numSpcs) & "s" & quote &
"," & quote & quote & ")  into tPad"
    else
      do "put format(" & quote & "%" & (numLevels) & "s" & quote & "," &
quote & quote & ")  into tPad"
      replace " " with numToChar(9) in tPad
    end if
    put last item of whatFolder into tFolderName
    if showType then put numToChar(9) & "folder" after tFolderName
    if numLevels <> 0 then
      put tPad & tFolderName into line (the number of lines of gHierList)+1
of gHierList
    else
      put tFolderName into line (the number of lines of gHierList)+1 of
gHierList
    end if
  end if
  put the files into temp
  sort temp
  repeat with x = 1 to the number of lines of temp
    if not(showHier) then
      put whatFolder & "/" & (line x of temp) into line (the number of lines
of gHierList)+1 of gHierList
    else
      put whatFolder & "/" & (line x of temp) into tPath
      put ((the number of items of tPath)) - gBaseLevels into numLevels
      if pDel <> "tabs" then
        do "put format(" & quote & "%" & (numLevels*numSpcs) & "s" & quote &
"," & quote & quote & ") into tPad"
      else
        do "put format(" & quote & "%" & (numLevels) & "s" & quote & "," &
quote & quote & ") into tPad"
        replace " " with numToChar(9) in tPad
      end if
      put line x of temp into tFile
      if showType then put addFileType(tFile) into tFile
      if numLevels <> 0 then
        put tPad & tFile into line (the number of lines of gHierList)+1 of
gHierList
      else
        put tFile into line (the number of lines of gHierList)+1 of
gHierList
      end if
    end if
  end repeat
  put the directories into tDirList
  sort tDirList
  repeat with x =  2 to the number of lines of tDirList
    directoryWalk (whatFolder & "/" & (line x of
tDirList)),showHier,pDel,showType
  end repeat
end directoryWalk

function addFileType what
  put offset(".",what) into tChar
  if tChar <> 0 then
    put char tChar to length(what) of what into tExt
    put
queryRegistry("HKEY_CLASSES_ROOT\"&(queryregistry("HKEY_CLASSES_ROOT\"&tExt&
"\")) & "\") into tType
  else
    put "" into tType
    put "" into tExt
  end if
  if tType = "" then
    if tExt <> "" then
      delete char 1 of tExt  -- remove "."
      put toUpper(tExt) && "File" into tType
    else
      put "File" into tType
    end if
  end if
  return what & numToChar(9) & tType
end addFileType


Hope this helps,

Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/


----- Original Message -----
From: "Scott Rossi" <scott at tactilemedia.com>
To: <metacard at lists.runrev.com>
Sent: Tuesday, August 27, 2002 2:17 PM
Subject: Get a List of Files


> How might one get a list of all files from a folder which contains nested
> folders and files several levels deep?
>
> folder1
> --> file1
> --> file2
> --> file3
> --> folderA
> ------> file1
> ------> file2
> ------> folderX
> ----------> file1
> ----------> file2
> ------> file 3
> --> file4
>
> Thanks & Regards,
>
> Scott Rossi
> Creative Director
> Tactile Media, Multimedia & Design
> -----
> E: scott at tactilemedia.com
> W: http://www.tactilemedia.com
>
> _______________________________________________
> metacard mailing list
> metacard at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/metacard
>




More information about the metacard mailing list