Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File created date

Status
Not open for further replies.

lencarne

Programmer
Feb 1, 2003
11
GB
Paradox can give you file modified date using Filesystem.time() but I need the file created date. I suppose its a Windows API call. Any advice please?
 
lencarne,

It seems you're right; the ObjectPAL RTL doesn't appear to contain anything that provides the actual creation date, instead of the last modified date.

There are API calls that can provide this information, however, they require certain structures to be initialized and passed, which is not something ObjectPAL is particularly good at. In most cases, this would mean the creation of a separate DLL using Delphi or some other Windows development language.

However, there is a hack available, though you may have to fiddle with it to get it to work properly for your version of Windows.

Consider, if you will, the following custom method:

Code:
method getFileCreateDate( strFileName String ) Datetime
; -------------------------------------------------------------------
; When passed a fully qualified filename, this returns the file's
; creation date, as opposed to the last modified date.  Note: This
; returned blankDate() as an error condition.
;
; Note that this was written using Paradox 9 under Windows 2000.
; Test heavily if using this under other versions of Windows,
; especially Windows 9.x.
; -------------------------------------------------------------------

var
   strFileTime,
   strLineData,
   strTempFile   String

   astrTokens    Array[] String
   ts            TextStream
   dtResult      DateTime
endVar

   dtResult = blank()
   strTempFile = "c:\\importme.txt"

   ; First, get the creation date of the target file into something
   ; we can work with.  Use "cmd" for Win 2K, NT, XP or 
   ; "command" for Win 9.x/ME.

   execute( "cmd /c dir /tc  " + strFileName +
            " > " + strTempFile,
            ExeHidden + ExeMinimized )

   ; import those results and parse out the tokens.
   ts.open( strTempFile, "r" )

   ; Note we're skipping several lines deliberately.  You may
   ; need to fiddle with this, as the data can change between
   ; different versions of Windows.
   ts.readLine( strLineData )
   ts.readLine( strLineData )
   ts.readLine( strLineData )
   ts.readLine( strLineData )
   ts.readLine( strLineData )
   ts.readLine( strLineData )
   ts.close()

   strLineData.breakApart( astrTokens )  ; parse the line

   ; Massage time into a convertable value
   strFileTime = astrTokens[ 2 ]
   strFileTime = strFileTime.substr( 1, 5 ) + ":00 " +
                 strFileTime.subStr( 6, 1 ) + "m"

   ; construct the return value
   dtResult = dateTime( dateVal( astrTokens[ 1 ] ) ) +
              dateTime( time( strFileTime ) )
   return dtResult

endMethod

Now, I created this as a separate method, one that can be called with something along these lines:

Code:
method pushButton(var eventInfo Event)
var
   dtCreateDate  Datetime
   strFileNname  String
endVar


   strFileName = "c:\\nospampls.txt"
   dtCreateDate = getFileCreateDate( strFileName )
   if dtCreateDate = blank() then
      msgStop( "Sorry", "We can't get the creation date for " +
                strFileName + ".  Please try again." )
   else
      msgInfo( "FYI", strFileName + " was created on " +
               string( dtCreateDate ) + "." )
   endIf

endMethod

I'll admit that the approach itself is rather ugly and suffers from a couple of weaknesses:

1. Unless you create a shortcut for calling this, you'll see a flash as the OS calls the command window. It sucks, but it does work.

2. Note that this particular implementation uses the /tc switch, which returns the creation date/time instead of the last modification. You'll need to fiddle with Win9x to see a) if the switch exists and b) whether or not its even necessary. (I seem to recall that 9.x always returned create date, but can't confirm that at the moment.)

3. It works because we've turned the problem into a data task. We get the OS to record the data into a text file, import that using the TextStream class, and then rip apart the results to create the data we actually need.

4. To sucessfully convert string time values into Time variable values, you need to format the string as [codeHH:MM:SS am[/code] or [codeHH:MM:SS pm[/code]. Since DIR under Win2K doesn't include the seconds, your results may not be completely accurate.

I know it's ugly, but it works on my machine. Hope your mileage doesn't vary too much...

-- Lance
 
Oh, crud!

#4 should read as follows:

4. To sucessfully convert string time values into Time variable values, you need to format the string as
Code:
HH:MM:SS am
or
Code:
HH:MM:SS pm
. Since DIR under Win2K doesn't include the seconds, your results may not be completely accurate.

Sorry...

-- Lance
 
Thanks Lance for your brave reply. Vlad Menkin, guess you know him from paradox comunity, has a friendly (& free!)API on his Web site which boasts getFileCreationDate(). I am going to try this first. Will let you know how I get on.
 
Vlad has done a great job for us Pdox guys with his API. Check it out. Thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top