Page 1 of 1

Getting a file's creation date

Posted: Thu May 10, 2012 12:45 am
by cosnet1BUSk1Aq
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

Re: Getting a file's creation date

Posted: Thu May 10, 2012 12:55 am
by mwieder
Check out "the detailed files".

Re: Getting a file's creation date

Posted: Thu May 10, 2012 11:54 am
by bn
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.
cosnet1BUSk1Aq.livecode.zip
(1.59 KiB) Downloaded 233 times
Kind regards

Bernd

Re: Getting a file's creation date

Posted: Thu May 10, 2012 11:56 am
by cosnet1BUSk1Aq
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

Re: Getting a file's creation date

Posted: Thu May 10, 2012 12:10 pm
by cosnet1BUSk1Aq
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?

Re: Getting a file's creation date

Posted: Thu May 10, 2012 12:22 pm
by bn
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

Re: Getting a file's creation date

Posted: Tue Oct 08, 2019 8:12 am
by atmosk
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

Posted: Tue Oct 08, 2019 11:38 am
by bogs
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.
atmosk wrote:
Tue Oct 08, 2019 8:12 am
here's how it's done in Richard's script mentioned above (with minor modification),
Richard who? I only see a sample posted in Bernd's post, and Mark's suggestion of using the detailed files items?
put item 4 of line 1 of the detailed files into tDate
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.

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.