How to get information about file (symlink, rights)

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Contact:

How to get information about file (symlink, rights)

Post by charms » Sun Apr 13, 2014 11:37 pm

I would like to create a file system browser that works on Mac, Win, Android, IOS. I have created a custom control that loads the files. The whole code is in the filesystem group. My problem is that I can't distinguish the files to the level I want to.

I use following commands to get the files:

Code: Select all

put the folders into tFolders
put the files into tFiles
The issues I have are following:
* The home, net and other folders are displayed as file out of some reason, why are these displayed as file? These are regular folders.
* Some of the symlinks are pointing to folders. I need to determine if it is a folder so that people can change in to this folder by clicking on it. How can I get more detailed information about the file?

Here the code from the "filesystem" group:

Code: Select all

on loadFilesInFolder pFolder
   local tFolders, tFiles, tRowAmount, tTop, tLeft, tInitTop, tInitLeft, tCounter, tCounterLeft
   set the folder to pFolder
   put empty into tFileArray
   
   put the folders into tFolders
   put the files into tFiles
   put empty into tAll
   
   repeat for each line tFolder in tFolders
      if char 1 of tFolder is not "." then
         put tFolder & "," & "1087" & return after tAll
      end if
   end repeat
   
   repeat for each line tFile in tFiles
      if char 1 of tFile is not "." then
         put tFile & "," & "1091" & return after tAll
      end if
   end repeat
   
   put round(the width of me / 100, 0) into tRowAmount
   
   put the top of me into tTop
   put the left of me into tLeft
   put the top of me into tInitTop
   put the left of me into tInitLeft
   
   put 1 into tCounter
   put 1 into tCounterLeft
   put "field" & tCounter into tName
   
   lock screen
   repeat for each line tA in tAll
      set the itemdel to ","
      put the item 1 of tA into tText
      put the item 2 of tA into tImage
      
      createFileButton tImage, tName, tText, tTop, tLeft
      if tCounterLeft is tRowAmount then
         add 80 to tTop
         put tInitLeft into tLeft
         put 1 into tCounterLeft
      else
         add 100 to tLeft
         add 1 to tCounterLeft
      end if
      add 1 to tCounter
      put "field" & tCounter into tName
   end repeat
   unlock screen
end loadFilesInFolder

on createFileButton pIcon, pName, pText, pTop, pLeft
   --create button pName in group "filesystem"
   create button pName in me
   set the icon of button pName to pIcon
   set the hiliteIcon of button pName to pIcon
   set the label of button pName to char 1 to 12 of word 1 of pText
   set the toolTip of button pName to pText
   set the width of button pName to 100
   set the height of button pName to 80
   set the left of button pName to pLeft
   set the top of button pName to pTop
   set the lockLoc of button pName to true
   set the threeD of button pName to false
   set the borderWidth of button pName to 0
   set the btType of button pName to true
end createFileButton

on createFolderButton
   
end createFolderButton

on removeButtons
   local a
   
   -- Lock the screen so that this is nice and fast
   lock screen
   -- Loop through all the controls in the stack. NOTE: we have to loop downwards to zero as we may be
   -- removing controls while in the loop - not doing this causes Badness.
   repeat with a = the number of controls down to 1
      -- Check the custom property "cPreviewControl" to see if this control is a thumbnail image and delete it.
      if the btType of control a is true then delete control a
   end repeat
   unlock screen
end removeButtons
Here the output of ls -l on the filesystem:

Code: Select all

charms:adstation$ ls -l /
total 16446
drwxrwxr-x+ 75 root  admin     2550 Apr 12 14:55 Applications
drwxr-xr-x+ 64 root  wheel     2176 Mar  2 12:27 Library
drwxr-xr-x@  2 root  wheel       68 Aug 25  2013 Network
drwxr-xr-x+  4 root  wheel      136 Nov 10 19:54 System
lrwxr-xr-x   1 root  wheel       49 Feb 21 18:55 User Information -> /Library/Documentation/User Information.localized
drwxr-xr-x   6 root  admin      204 Feb 21 18:55 Users
drwxrwxrwt@  6 root  admin      204 Apr 13 22:51 Volumes
drwxr-xr-x@ 39 root  wheel     1326 Mar  1 19:06 bin
drwxrwxr-t@  3 root  admin      102 Apr 11 21:18 cores
dr-xr-xr-x   3 root  wheel     4774 Mar 30 01:27 dev
lrwxr-xr-x@  1 root  wheel       11 Nov 10 19:48 etc -> private/etc
dr-xr-xr-x   2 root  wheel        1 Mar 30 01:27 home
-rwxr-xr-x@  1 root  wheel  8393408 Feb 18 00:23 mach_kernel
dr-xr-xr-x   2 root  wheel        1 Mar 30 01:27 net
drwxr-xr-x   3 root  wheel      102 Sep 27  2012 opt
drwxr-xr-x@  6 root  wheel      204 Nov 10 19:56 private
drwxr-xr-x@ 62 root  wheel     2108 Mar  1 19:06 sbin
lrwxr-xr-x@  1 root  wheel       11 Nov 10 19:48 tmp -> private/tmp
drwxr-xr-x@ 12 root  wheel      408 Feb 21 23:39 usr
lrwxr-xr-x@  1 root  wheel       11 Nov 10 19:48 var -> private/var

Attachments
file_browser.livecode.zip
(3.99 KiB) Downloaded 244 times

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to get information about file (symlink, rights)

Post by FourthWorld » Mon Apr 14, 2014 12:36 am

Instead of "the files" try "the detailed files".
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Contact:

Re: How to get information about file (symlink, rights)

Post by charms » Mon Apr 14, 2014 5:18 pm

Hi FourthWorld,

Thanks for your message. However I'm still puzzled. For example "home" and "net" are not displayed by "the folders". These are regular folders which can be read by all users. I just can't figure out why these are not displayed with "the folders". Also I don't see any value in "the detailed files" that can be used to determine if a file is a symlink apart from the 11 bytes. But another documents could also have 11 bytes.

Are there any other options?

The detailed files form returns a list of files, one file per line. Each line contains the following attributes, separated by commas:
* The file's name, URL-encoded
* The file's size in bytes (on Mac OS and OS X systems, the size of the file's data fork)
* The resource fork size in bytes (Mac OS and OS X systems only)
* The file's creation date in seconds (Mac OS, OS X, and Windows systems only)
* The file's modification date in seconds
* The file's last-accessed date in seconds (Unix, OS X and Windows systems only)
* The file's last-backup date in seconds (Mac OS and OS X systems only)
* The file's owner (Unix and OS X systems only)
* The file's group owner (Unix and OS X systems only)
* The file's access permissions
* The file's creator and file type (Mac OS and OS X only)

Thanks,
Chris
Attachments
folders.tiff
folders.tiff (31.72 KiB) Viewed 6444 times

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to get information about file (symlink, rights)

Post by FourthWorld » Mon Apr 14, 2014 5:57 pm

For that one piece of information on Linux systems you'll need to use LiveCode's shell function to call "ls -li".
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Contact:

Re: How to get information about file (symlink, rights)

Post by charms » Wed Apr 16, 2014 12:32 am

Thanks fof the feedback. How would i do this on mobile? It seems the shell command doesn't work on mobile. I need to be able to browse files on Android and iOS.

Kind regards,
Chris

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to get information about file (symlink, rights)

Post by Klaus » Wed Apr 16, 2014 11:51 am

Hi Chris,

I'm afraid on mobile you will need to stick to:

Code: Select all

put the [long] folders into tFolders
put the [long] files into tFiles

Best

Klaus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to get information about file (symlink, rights)

Post by FourthWorld » Wed Apr 16, 2014 2:29 pm

I'm impressed by the attention to detail, but I wonder if it needs to be a show-stopper for your first version.

On iOS, users are generally insulated from having to think about the file system at all, and on Android, where there are many excellent file managers, even the best of them like ES File Explorer don't seem to provide distinction for sym links, at least not that I can see.

This is understandable given that the only files users should be working with directly are their own, which will be regular files. And in terms of the sorts of actions you want to provide support for, does it make a critical difference in your v1.0?

You're welcome to submit a feature request for a LiveCode function to determine symlinks, but since this can already be done for non-mobile platforms via shell and the need on mobile is a rare one, it may not be a high priority, leaving you with the option of writing that feature yourself and submitting a pull request to have it considered for inclusion in the engine, or writing an external to handle that once the Android externals API is completed.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to get information about file (symlink, rights)

Post by FourthWorld » Wed Apr 16, 2014 2:31 pm

charms wrote:Thanks for your message. However I'm still puzzled. For example "home" and "net" are not displayed by "the folders". These are regular folders which can be read by all users. I just can't figure out why these are not displayed with "the folders".
If they are regular folders this may be a bug. You can submit a bug report with the recipe for reproducing it to:
http://quality.runrev.com/
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Contact:

Re: How to get information about file (symlink, rights)

Post by charms » Fri Apr 18, 2014 6:05 pm

Hi FourthWorld,

Thanks, I have done that.

Kind regards,
Chris

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: How to get information about file (symlink, rights)

Post by mwieder » Fri Apr 18, 2014 9:29 pm

There's an existing bug on this (http://quality.runrev.com/show_bug.cgi?id=10690), but note that you can use the aliasreference() function to dereference aliases or symbolic links.

Post Reply