[AccessD] fso.DeleteFile Strange behaviour!?

Curtis, Andrew (WAPL) andrew.curtis at wapl.com.au
Wed Feb 11 19:55:23 CST 2004


Suggest you use date / time MODIFIED instead. Creation date is
unreliable after a delete because when a file is deleted, it is not
truly removed, it simply has its first character scrambled, thus hiding
it from the OS, but retrievable via undelete methods. Recreating the
same file in the same place immediately becomes a bit grey.


Andrew Curtis

-----Original Message-----
From: S D [mailto:accessd667 at yahoo.com] 
Sent: Wednesday, 11 February 2004 4:01 PM
To: accessd
Subject: [AccessD] fso.DeleteFile Strange behaviour!?


Hi group,
 
I'm using FileSystemObject to delete a MDB file. 
After that I'm creating a new MDB.
Then i'm using the .DateCreated method to get the the info about when
the file was created. I checked this in the help: "Returns the date and
time that the specified file or folder was created. Read-only."
 
However the time it returns is the date\time combination of when I
created the DB for the first time.
 
EG: I'm starting the application at 8:00. I then show on screen the
date\time the temp (analyses) db was created, let's say that it was
created on 10 feb 2004 16:34:56. I then decide to create a new temp db.
I press the button and it deletes the file, creates a new one and adds
tables to it. Then I show the user the .DateCreated wich shows 8:00.
When I stay in the program and do the above at 8:15 the .DateCreated
method returns again 8:00!!! When I look in Explorer the DateCreated
column shows 8:00 and the DateModified shows 8:15?!!? QUA PASA. WHY is
the date created 8:00? I've checked in Explorer that the file is gone
after the deletefile statement.
 
Any ideas?
 
Sander
Here's part of my code:
FORM LOAD:
   'Create temporary database
   blnCreateTables = CreateTempDatabase(LOCATION_TEMP_DB, TEMP_DB_NAME)
   
   If blnCreateTables Then
      'Create tables
      Call CreateTables(LOCATION_TEMP_DB, TEMP_DB_NAME)
...
...
 
Function CreateTempDatabase(strPath As String, strDbName As String) As
Boolean
On Error GoTo Err_CreateTempDatabase
   Dim dbDestination As DAO.Database
   Dim blnDbExists As Boolean
   Dim blnCreateDB As Boolean
   
   'Check if file exists
   blnDbExists = FileExists(strPath & strDbName)
   If blnDbExists Then
      Select Case MsgBox("Temporary database EXISTS. Do you want to
DELETE it and create a new one?", vbYesNo + vbInformation +
vbDefaultButton1, "Temporary database exists")
      Case vbYes
         'Delete file!
         If DeleteFile(strPath & strDbName) Then
            blnCreateDB = True
....
....
 
   'Create TEMPDB
   If blnCreateDB Then
      Set dbDestination = Workspaces(0).CreateDatabase(strPath &
strDbName, DB_LANG_GENERAL)
   End If
   'Set return value
   CreateTempDatabase = blnCreateDB
'errorhandling
END FUNCTION
 
 
 
Public Function DeleteFile(strFileName As String) As Boolean
On Error GoTo Err_DeleteFile
   Dim fso As FileSystemObject
   Dim file As String
   Dim strFileNameLDB As String
   
   file = strFileName ' change to match the file w/Path
   Set fso = New FileSystemObject
   'Set fso = CreateObject("Scripting.FileSystemObject")
   strFileNameLDB = "C:\Program Files\Switchdatabase\Temp_Db_Switch.ldb"
   If fso.FileExists(strFileName) Then
       fso.DeleteFile strFileName, True
       If fso.FileExists(strFileNameLDB) Then
         fso.DeleteFile strFileNameLDB, True
       End If
       'return value
       DeleteFile = True
   Else
      'return value
      DeleteFile = False
   End If
Exit_DeleteFile:
     Exit Function
     
Err_DeleteFile:
     MsgBox Err.Number & vbCrLf & _
     Err.Description & vbCrLf & _
     "Location: DeleteFile()"
     Resume Exit_DeleteFile
End Function

 
 
Function CheckNewFile(strFile As String) As String
On Error GoTo Err_CheckNewFile
   Dim objFileSys As FileSystemObject
   Dim objFile As file
   Dim strFileName As String
   Dim strNewDateCreated As String
   Set objFileSys = New FileSystemObject
   strFileName = strFile
   If objFileSys.FileExists(strFileName) Then
      Set objFile = objFileSys.GetFile(strFileName)
      'Get file created value
      With objFile
         strNewDateCreated = .DateCreated
      End With
   Else
      'File does NOT exist!
      strNewDateCreated = vbNullString
      GoTo Exit_CheckNewFile
   End If
   'Set returnvalue
   CheckNewFile = strNewDateCreated
....errrorhandling
End Function


---------------------------------
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com


CONFIDENTIAL COMMUNICATION
If you receive this confidential communication by mistake, please contact the sender immediately by return electronic mail.
Worsley Alumina Pty Ltd ABN 58 008 905 155 is the manager of
the Worsley Joint Venture - Bauxite/Alumina Operation. Liability and responsibility of the Joint Venturers is several in accordance with the following schedule of participating interests: Billiton Aluminium (RAA) Pty Ltd 56 percent, Billiton Aluminium (Worsley) Pty Ltd 30 percent, Japan Alumina Associates (Australia) Pty Ltd 10 percent, Nissho Iwai Alumina Pty Limited 4 percent.



More information about the AccessD mailing list