Page 1 of 2
Reading file and folder dates
Posted: Thu Sep 16, 2021 4:43 pm
by marksmithhfx
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
Re: Reading file and folder dates
Posted: Thu Sep 16, 2021 5:01 pm
by jmburnod
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
Re: Reading file and folder dates
Posted: Thu Sep 16, 2021 5:20 pm
by Bernard
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,
Re: Reading file and folder dates
Posted: Thu Sep 16, 2021 5:21 pm
by Klaus
Hi Mark,
Jean-Marcs solution will unfortunately not work on iOS.
Hint, no need to mess with the DEFAULTFOLDER anymore!
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
Re: Reading file and folder dates
Posted: Fri Sep 17, 2021 2:44 pm
by marksmithhfx
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
Could you point me in the right direction so I can understand why it's not working?
Thanks
Mark
Re: Reading file and folder dates
Posted: Fri Sep 17, 2021 2:46 pm
by marksmithhfx
Bernard wrote: ↑Thu Sep 16, 2021 5:20 pm
dropboxListFolder pAccessToken, pPath, pRecursive, pIncludeMediaInfo, [pCallback]
Thanks Bernard, I got that working!
Mark
Re: Reading file and folder dates
Posted: Fri Sep 17, 2021 2:50 pm
by Klaus
Hi Mark,
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
Re: Reading file and folder dates
Posted: Fri Sep 17, 2021 10:20 pm
by marksmithhfx
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
Re: Reading file and folder dates
Posted: Fri Sep 17, 2021 10:33 pm
by marksmithhfx
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
Re: Reading file and folder dates
Posted: Fri Sep 17, 2021 10:55 pm
by marksmithhfx
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
Mark
Re: Reading file and folder dates
Posted: Sat Sep 18, 2021 1:58 am
by mtalluto
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.
Re: Reading file and folder dates
Posted: Sat Sep 18, 2021 1:35 pm
by marksmithhfx
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
Re: Reading file and folder dates
Posted: Sun Sep 19, 2021 12:19 am
by kdjanz
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
Re: Reading file and folder dates
Posted: Sun Sep 19, 2021 6:29 pm
by marksmithhfx
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
Re: Reading file and folder dates
Posted: Mon Sep 20, 2021 4:19 am
by kdjanz
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?