Getting a file's creation date
Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 10
- Joined: Wed Apr 18, 2012 9:58 pm
Getting a file's creation date
Hi,
I am parsing a text file and I have managed to figure out how to open the text file read its contents and dump to a text field. From that I will parse the contents to Grid field and one of the columns of the grid will be the files creation date. I have searched and found that you can read a directory of files and get the attributes from it but not on a single file that the user has selected.
Here is my code for the button to select the file and read it into a field "inkReport" but what I want to do is have the first line be the files creation date.
on preOpenStack
put empty into field "inkReport"
end preOpenStack
on mouseUp
answer file "Select Ink Coverage Report file:" with type Text
put it into tFile
processFile tFile
end mouseUp
on processFile pFile
open file pFile for read
read from file pFile until EOF
put it into field "inkReport"
close file pFile
end processFile
I am parsing a text file and I have managed to figure out how to open the text file read its contents and dump to a text field. From that I will parse the contents to Grid field and one of the columns of the grid will be the files creation date. I have searched and found that you can read a directory of files and get the attributes from it but not on a single file that the user has selected.
Here is my code for the button to select the file and read it into a field "inkReport" but what I want to do is have the first line be the files creation date.
on preOpenStack
put empty into field "inkReport"
end preOpenStack
on mouseUp
answer file "Select Ink Coverage Report file:" with type Text
put it into tFile
processFile tFile
end mouseUp
on processFile pFile
open file pFile for read
read from file pFile until EOF
put it into field "inkReport"
close file pFile
end processFile
-
- VIP Livecode Opensource Backer
- Posts: 3211
- Joined: Mon Jan 22, 2007 7:36 am
- Location: Berkeley, CA, US
- Contact:
Re: Getting a file's creation date
Check out "the detailed files".
-
- VIP Livecode Opensource Backer
- Posts: 3465
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Getting a file's creation date
Hi cosnet1BUSk1Aq,
as Mark says.
since some of the things are not quite obvious when retrieving the detailed files I made a little stack to get info on a file.
Kind regards
Bernd
as Mark says.
since some of the things are not quite obvious when retrieving the detailed files I made a little stack to get info on a file.
Kind regards
Bernd
-
- VIP Livecode Opensource Backer
- Posts: 10
- Joined: Wed Apr 18, 2012 9:58 pm
Re: Getting a file's creation date
I did see that function. The issue is that is for parsing an entire directory of files. I already have my file.. I guess I can build a kind of work around to get the detail of a specific file. Let me play with the function.
Suggestion: you should index every word in the dictionary. if you search for "the details" nothing comes up.. or even if you search for details.
I see just before I posted this that Bernd has something too.. Thanks to both of you.
Bruce
Suggestion: you should index every word in the dictionary. if you search for "the details" nothing comes up.. or even if you search for details.
I see just before I posted this that Bernd has something too.. Thanks to both of you.
Bruce
Last edited by cosnet1BUSk1Aq on Thu May 10, 2012 12:11 pm, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 10
- Joined: Wed Apr 18, 2012 9:58 pm
Re: Getting a file's creation date
Hi Bernd,
Thanks for the code. It was something I had in mind as what I would do (not as elegant of course and much longer for a newbie to do).
I notice you have a series of saving current defaults for delimiter and folder and then replacing them with my files folder and path delimiters. Are you doing that so it does not spoil other parts of a program that might be using different defaults or are there inherent defaults that should not be changed by a program?
Thanks for the code. It was something I had in mind as what I would do (not as elegant of course and much longer for a newbie to do).
I notice you have a series of saving current defaults for delimiter and folder and then replacing them with my files folder and path delimiters. Are you doing that so it does not spoil other parts of a program that might be using different defaults or are there inherent defaults that should not be changed by a program?
-
- VIP Livecode Opensource Backer
- Posts: 3465
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Getting a file's creation date
Hi Bruce,
as for the itemDelimiter I have to change it to "/" to get at the file name and the folder name. Later I want to get "item x of tAllFiles" but the itemdelimiter is ",". Here it is important to change the itemDelimiter back.
As for the default folder it is not strictly necessary to set it back in your case, in other cases it might become a problem.
So it is a bit wordy but a reminder that one easily forgets in a long handler that the itemDelimiter was changed 50 lines above and now I want to use it for a comma delimited list and don't know why my code does not work. It makes life easier to restore things one has changed.
Kind regards
Bernd
as for the itemDelimiter I have to change it to "/" to get at the file name and the folder name. Later I want to get "item x of tAllFiles" but the itemdelimiter is ",". Here it is important to change the itemDelimiter back.
As for the default folder it is not strictly necessary to set it back in your case, in other cases it might become a problem.
So it is a bit wordy but a reminder that one easily forgets in a long handler that the itemDelimiter was changed 50 lines above and now I want to use it for a comma delimited list and don't know why my code does not work. It makes life easier to restore things one has changed.
Kind regards
Bernd
Re: Getting a file's creation date
As this is the first result from Google for "livecode file creation date" and no other thread actually answers it either (at least when going over them semi-superficially) here's how it's done in Richard's script mentioned above (with minor modification),
Code: Select all
on mouseUp
put item 4 of line 1 of the detailed files into tDate
convert tDate to long date and long time
answer tDate
end mouseUp
Re: Getting a file's creation date
UMMmm...
Having resurrected a number of posts so old even I could smell the rigorous coming off them, I don't want to sound too critical here atmosk, so please don't take it that way, but I had some questions about your post.
This may (or may not) even be where you want to be looking
The script is easy enough to turn into a function though, you may want to try it that way so it can be used over and over again.
Having resurrected a number of posts so old even I could smell the rigorous coming off them, I don't want to sound too critical here atmosk, so please don't take it that way, but I had some questions about your post.
Richard who? I only see a sample posted in Bernd's post, and Mark's suggestion of using the detailed files items?
The second is about the code itself. while it is plenty short, without a loop (to cover every file in a given directory) or some other means of determining which file we're working on (such as an if/then or case/select structure), all I see you getting here is the detail of the first file in the list of files of the default folder.put item 4 of line 1 of the detailed files into tDate
This may (or may not) even be where you want to be looking

The script is easy enough to turn into a function though, you may want to try it that way so it can be used over and over again.
