Help with Bug #19550: Add support for symlinks to standalone builder

Mark Wieder ahsoftware at sonic.net
Sat Jul 21 17:58:36 CEST 2018


Brian-

Here's the code I use in PowerTools to determine in a cross-platform way 
whether a filespec is a file or a folder. The Windows code is pretty 
stupid, just looking at the file extension, but I couldn't think of a 
better way to figure it out. HTH.

/**
* ----------------------------------------
* IsFolder
*
* Determine whether the given filespec is a folder (true) or a file (false)
* @pFileSpec : path reference to a folder or file
* ----------------------------------------
*/
private function isFolder pFileSpec
    local tIsFolder
    local tFile, tFiles
    local tTarget
    local tData
    local tAlias
    local tDefaultFolder

    put false into tIsFolder
    if there is a folder pFileSpec then
       -- see if it's an LC8 extension
       put FilesOfFolder(pFileSpec) into tFiles
       filter tFiles with "*.lcm"
       if tFiles is empty then
          -- not an extension, it's a real folder
          put true into tIsFolder
       end if
    else
       -- must be a file reference
       put aliasreference(pFileSpec) into tAlias
       switch the platform
          case "Win32"
             -- aliasreference returns empty on OSX, filespec on linux
             if tAlias is not empty and tAlias is not pFileSpec then
                if IsFolder(tAlias) then
                   put true into tIsFolder
                else
                   put false into tIsFolder
                end if
             end if
             break
          case "MacOS"
             -- ignore Windows link files
             if char -4 to -1 of pFileSpec is ".lnk" then
                put false into tIsFolder
             end if
             break
          case "linux"
             -- ignore Windows link files
             if char -4 to -1 of pFileSpec is ".lnk" then
                put false into tIsFolder
             else
                put shell("ls -l" && quote & pFileSpec & quote) into tFile
                if char 1 of tFile is "l" then
                   set the itemdelimiter to ">"
                   put item -1 of tFile into tTarget
                   if the number of lines in tTarget > 1 then
                      put true into tIsFolder
                   end if
                end if
             end if
       end switch
    end if
    return tIsFolder
end isFolder

-- 
  Mark Wieder
  ahsoftware at gmail.com



More information about the use-livecode mailing list