Reading file and folder dates

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Reading file and folder dates

Post by marksmithhfx » Thu Sep 16, 2021 4:43 pm

I have a need to read file dates on iOS and on Dropbox files. Is there any way to do this in LC?

Thanks
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Reading file and folder dates

Post by jmburnod » Thu Sep 16, 2021 5:01 pm

Hi Mark
You may use "detailed files" like this:

Code: Select all

on mouseup
   answer folder "open"
   set the defaultfolder to it
   put the detailed files
end mouseup
Check it in dictionary for the results details

Best regards
Jean-Marc
https://alternatic.ch

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Reading file and folder dates

Post by Bernard » Thu Sep 16, 2021 5:20 pm

dropboxListFolder pAccessToken, pPath, pRecursive, pIncludeMediaInfo, [pCallback]

...

".tag": "file",
"name": "Prime_Numbers.txt",
"id": "id:a4ayc_80_OEAAAAAAAAAXw",
"client_modified": "2015-05-12T15:50:38Z",
"server_modified": "2015-05-12T15:50:38Z",
"rev": "a1c10ce0dd78",
"size": 7212,

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Reading file and folder dates

Post by Klaus » Thu Sep 16, 2021 5:21 pm

Hi Mark,

Jean-Marcs solution will unfortunately not work on iOS.

Hint, no need to mess with the DEFAULTFOLDER anymore! :D

Code: Select all

...
answer folder "open"
put files(IT,"detailed-UTF8")
...
Or better:

Code: Select all

...
answer folder "open"
put URLDECODE(files(IT,"detailed-UTF8"))
...
Best

laus

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: Reading file and folder dates

Post by marksmithhfx » Fri Sep 17, 2021 2:44 pm

Klaus wrote:
Thu Sep 16, 2021 5:21 pm

Code: Select all

...
answer folder "open"
put files(IT,"detailed-UTF8")
...
Hi Klaus,

I tried sticking that in a button and running it on iOS, but nothing appeared. Also, I could not find any documentation in the dictionary for

Code: Select all

answer folder "open"
Could you point me in the right direction so I can understand why it's not working?

Thanks
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: Reading file and folder dates

Post by marksmithhfx » Fri Sep 17, 2021 2:46 pm

Bernard wrote:
Thu Sep 16, 2021 5:20 pm
dropboxListFolder pAccessToken, pPath, pRecursive, pIncludeMediaInfo, [pCallback]
Thanks Bernard, I got that working!

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Reading file and folder dates

Post by Klaus » Fri Sep 17, 2021 2:50 pm

Hi Mark,

Code: Select all

...
answer folder "open"
...
Here "open" ist just the very very short(read -> LAZY) prompt visible to the user in the file dialog.
This might be better understandable:

Code: Select all

...
answer folder "Please select a folder to open..."
...
:-)

But this does not work on mobile (iOS/Android) since we do not have access to these filesystems
due to security reasons (Sandboxing).


Best

Klaus

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: Reading file and folder dates

Post by marksmithhfx » Fri Sep 17, 2021 10:20 pm

Well, more work than I was hoping for but for the sake of anyone who might be following in my footsteps, here is the solution I came up with.

Goal: to acquire the last modified datetime (in seconds) of a single specific file in iOS or Dropbox

In iOS the solution is not bad since the "detailed" option of the files command returns the datetime in seconds:

Code: Select all

on mouseup
   put files (specialfolderpath("documents"), "detailed") into tTemp
   filter lines of tTemp with "todoitems.*"
   -- put tTemp into field "testOut"
   answer item 5 of tTemp -- item 5 contains the last modified date in seconds
end mouseup
In DropBox its a little more work because the date returned is in a proprietary format: YYYY/MM/DDTHH:MM:SS

Perhaps someone can see a faster or better way to process this...

Code: Select all

   dropboxListFolder tAccessToken, "", pRecursive, pIncludeMediaInfo -- "" is pPath
   
   if it is empty then
      answer "Access Token not valid"
      exit to top
   end if
   
   put JsonImport(it) into tArray

   -- process the Array to find date todoitems.sqlite was last modified
   
   repeat for each key tKey in tArray["entries"]
      if tArray["entries"][tKey]["name"] = "todoitems.sqlite" then
         -- parse date and time
         put tArray["entries"][tKey]["client_modified"] into tString -- last modified date YYYY-MM-DDTHH:MM:SS
         put offset ("T",tString) into tPos
         if tPos > 1 then
            put char 1 to tPos-1 of tString into tDate -- YYYY-MM-DD
            replace "-" with "/" in tDate -- YYYY/MM/DD
            set itemdelimiter to "/"
            put char 3 to 4 of tDate into YR -- YY
            delete item 1 of tDate -- MM/DD
            put "/" & YR after tDate -- MM/DD/YY
            put char tPos+1 to -2 of tString into tTime -- HH:MM:SS
            put tDate & " " & tTime into DT -- MM/DD/YY HH:MM:SS
            convert DT to seconds
            answer DT
            exit repeat
         end if
      end if
   end repeat
BTW, big thanks to Bangkok for posting the Demo DropBox Library viewtopic.php?f=11&t=33901&p=206382&hil ... ry#p206382. I was able to use that as the basis for my DropBox solution above.

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: Reading file and folder dates

Post by marksmithhfx » Fri Sep 17, 2021 10:33 pm

jmburnod wrote:
Thu Sep 16, 2021 5:01 pm
Hi Mark
You may use "detailed files" like this:

Code: Select all

on mouseup
   answer folder "open"
   set the defaultfolder to it
   put the detailed files
end mouseup
Check it in dictionary for the results details

Best regards
Jean-Marc
Hey Jean-Marc, thanks for the "detailed files" lead. That was very helpful.

Cheers,
Mark
Last edited by marksmithhfx on Fri Sep 17, 2021 11:11 pm, edited 1 time in total.
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: Reading file and folder dates

Post by marksmithhfx » Fri Sep 17, 2021 10:55 pm

BTW, this is all in aid of trying to sync copies of a database across a users devices. The simple solution I have come up with is to maintain a master copy in a dropbox folder. Every time the app is opened on a device, it checks the master "last mod date" and if the master is newer then it downloads the newer version. Likewise, when the session is ended the app pushes the current copy to dropbox (which then becomes the new master). Time will tell if this strategy works.

I'd like to maintain the option of using the app "offline", hence the pushing and pulling instead of just reading and writing to a single master copy. The other limitation of this approach is it is not multi-user. It is presuming that this is a single user app (which mine is) and the user would just like to maintain content compatibility across devices.

Open to any other suggestions you might have, or even fully developed solutions :D

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

mtalluto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 125
Joined: Tue Apr 11, 2006 7:02 pm
Location: Seattle, WA
Contact:

Re: Reading file and folder dates

Post by mtalluto » Sat Sep 18, 2021 1:58 am

Using the system clock on desktops for these things can be problematic. Not everyone has their clock synced to an outside source. Mobile devices are more likely to have the correct time.

You can store version details in your records and compare those in your sync routine. This is side steps the clock issue.
Mark Talluto
--
Canela
design - develop - deploy: https://appli.io
Database and Cloud for LiveCode Developers: https://livecloud.io
Company: https://canelasoftware.com

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: Reading file and folder dates

Post by marksmithhfx » Sat Sep 18, 2021 1:35 pm

mtalluto wrote:
Sat Sep 18, 2021 1:58 am
Using the system clock on desktops for these things can be problematic. Not everyone has their clock synced to an outside source. Mobile devices are more likely to have the correct time.

You can store version details in your records and compare those in your sync routine. This is side steps the clock issue.
Good point. Thanks for the suggestion Mark.

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

kdjanz
Posts: 300
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Reading file and folder dates

Post by kdjanz » Sun Sep 19, 2021 12:19 am

You could even store the time as part of the file name when you save it. If the Dropbox number is bigger than the local number then update.

Kelly

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: Reading file and folder dates

Post by marksmithhfx » Sun Sep 19, 2021 6:29 pm

kdjanz wrote:
Sun Sep 19, 2021 12:19 am
You could even store the time as part of the file name when you save it. If the Dropbox number is bigger than the local number then update.

Kelly
Thanks Kelly, I was emailing Mike Kerner about this issue when I hit on the same idea. It also solves another thorny problem I was facing: namely Zulu time and how to convert back and forth to local time. Dropbox saves your files using Zulu time (GMT) which for 99% of us will not be the same time on our iDevice. So in order for this file date/time comparison to work, I needed to find a way to convert Zulu time to local time, and I don't have a clue where I would start looking for that.

With this suggestion, livecode already returns the file date/time in seconds so it becomes easy to append to the filename and then parse it out (from dropbox) for comparison with the local file. A grand suggestion, so thank you for mentioning it. Off to the bench to code it up and see how it works...

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

kdjanz
Posts: 300
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Reading file and folder dates

Post by kdjanz » Mon Sep 20, 2021 4:19 am

I was also thinking of something even more basic:

What if the first time a file was saved it was ”Data0000000000000001.dat” and then each further save from any source just increments that by 1. You don’t really need to care about the date or time so long as you know that you have the newest master data.

Just thinking about multi users - maybe you could give each user a prefix - so you could have “Joe0000000043” and “Sam000000021” and as long as profiles and passwords matched, you could have multiple users of the program accessing whichever datasets they have credentials for.

So… do you really care about time and date?

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”