Reading file and folder dates
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Reading file and folder dates
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
Thanks
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Reading file and folder dates
Hi Mark
You may use "detailed files" like this:
Check it in dictionary for the results details
Best regards
Jean-Marc
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
Best regards
Jean-Marc
https://alternatic.ch
Re: Reading file and folder dates
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,
...
".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
Hi Mark,
Jean-Marcs solution will unfortunately not work on iOS.
Hint, no need to mess with the DEFAULTFOLDER anymore!
Or better:
Best
laus
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")
...
Code: Select all
...
answer folder "open"
put URLDECODE(files(IT,"detailed-UTF8"))
...
laus
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Reading file and folder dates
Hi Klaus,Klaus wrote: ↑Thu Sep 16, 2021 5:21 pmCode: Select all
... answer folder "open" put files(IT,"detailed-UTF8") ...
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"
Thanks
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Reading file and folder dates
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
Targets: Mac, iOS
Re: Reading file and folder dates
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:
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
Code: Select all
...
answer folder "open"
...
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
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Reading file and folder dates
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:
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...
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
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
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
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Reading file and folder dates
Hey Jean-Marc, thanks for the "detailed files" lead. That was very helpful.jmburnod wrote: ↑Thu Sep 16, 2021 5:01 pmHi Mark
You may use "detailed files" like this:
Check it in dictionary for the results detailsCode: Select all
on mouseup answer folder "open" set the defaultfolder to it put the detailed files end mouseup
Best regards
Jean-Marc
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
Targets: Mac, iOS
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Reading file and folder dates
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
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
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
-
- VIP Livecode Opensource Backer
- Posts: 125
- Joined: Tue Apr 11, 2006 7:02 pm
- Location: Seattle, WA
- Contact:
Re: Reading file and folder dates
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.
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
--
Canela
design - develop - deploy: https://appli.io
Database and Cloud for LiveCode Developers: https://livecloud.io
Company: https://canelasoftware.com
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Reading file and folder dates
Good point. Thanks for the suggestion Mark.mtalluto wrote: ↑Sat Sep 18, 2021 1:58 amUsing 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
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
Re: Reading file and folder dates
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
Kelly
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
- Location: London, UK
Re: Reading file and folder dates
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
Targets: Mac, iOS
Re: Reading file and folder dates
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?
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?