nedrub
asked on
File migration
I need to copy files from one W2K server to another.
Problem is, I need to do it without modifying the DateLastAccessed property.
How can I do this?
I've tried copying the file from DOS, and dragging and droping via the interface - no dice (moving the files from one location on a drive to another was OK, but moving to another drive was not).
I've also tried writing a VB program, thinking I'd be able to modify the property - through the FileSytemObject the property is read-only.
HELP!
Problem is, I need to do it without modifying the DateLastAccessed property.
How can I do this?
I've tried copying the file from DOS, and dragging and droping via the interface - no dice (moving the files from one location on a drive to another was OK, but moving to another drive was not).
I've also tried writing a VB program, thinking I'd be able to modify the property - through the FileSytemObject the property is read-only.
HELP!
ASKER
Thanks Irmoore . . .
It works, but . . .
If I'm migrating files from \\PC1\sharename the files last accessed property is updated.
If I'm migrating files from D:\stuff\sharedDir (on PC1) the files last accessed property is not updated, but when I restore to PC2 I get the files in the E:\stuff\sharedDir directory (I want them in E:\sharedDir).
I have tried backing up files from \\PC1\sharename from PC1 - no surprise that results were as above.
It works, but . . .
If I'm migrating files from \\PC1\sharename the files last accessed property is updated.
If I'm migrating files from D:\stuff\sharedDir (on PC1) the files last accessed property is not updated, but when I restore to PC2 I get the files in the E:\stuff\sharedDir directory (I want them in E:\sharedDir).
I have tried backing up files from \\PC1\sharename from PC1 - no surprise that results were as above.
ASKER
Thanks Irmoore . . .
It works, but . . .
If I'm migrating files from \\PC1\sharename the files last accessed property is updated.
If I'm migrating files from D:\stuff\sharedDir (on PC1) the files last accessed property is not updated, but when I restore to PC2 I get the files in the E:\stuff\sharedDir directory (I want them in E:\sharedDir).
I have tried backing up files from \\PC1\sharename from PC1 - no surprise that results were as above.
It works, but . . .
If I'm migrating files from \\PC1\sharename the files last accessed property is updated.
If I'm migrating files from D:\stuff\sharedDir (on PC1) the files last accessed property is not updated, but when I restore to PC2 I get the files in the E:\stuff\sharedDir directory (I want them in E:\sharedDir).
I have tried backing up files from \\PC1\sharename from PC1 - no surprise that results were as above.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, vinnyd79
I feel like I'm getting somewhere now.
Your post led me to do a search for SetFileTime on google, which led me to:
http://www.allapi.net/apilist/apifunction.php?apifunction=SetFileTime
(which has code for setting create, modify, and access time of a file to the current system time)
I've butchered it a bit and it works, sort of . . .
I've got plenty of msgboxes in there to keep track of what is going on:
MSGBOX 1: date of last access of source file
MSGBOX 2: date of last access of destination file after copy
MSGBOX 3: date of last access of destination file after SetFileDate
MSGBOX 4: date of last access of destination file after CloseFile
The date is what I want at MSGBOX 3, but the close "touches" the file and the date is set to the system time.
Help!!
My code:
'========================= ========== ==========
'This project needs a Common Dialog box, named CDBox.
' (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
' and select Microsoft Common Dialog control)
Dim fso As New FileSystemObject
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'KPDTeam@Allapi.net
Dim m_Date As Date, lngHandle As Long
Dim udtFileTime As FILETIME
Dim udtCreateTime As FILETIME
Dim udtLastWriteTime As FILETIME
Dim udtLocalTime As FILETIME
Dim udtDummyTime As FILETIME
Dim udtSystemTime As SYSTEMTIME
'Set the dialog's title
CDBox.DialogTitle = "Choose a file ..."
'Set the dialog's filter
CDBox.Filter = "All Files (*.*)|*.*"
'Show the 'Open File'-dialog
CDBox.ShowOpen
MsgBox "1 (source before copy): " & fso.GetFile(CDBox.FileName ).DateLast Accessed
m_Date = fso.GetFile(CDBox.FileName ).DateLast Accessed
udtSystemTime.wYear = Year(m_Date)
udtSystemTime.wMonth = Month(m_Date)
udtSystemTime.wDay = Day(m_Date)
udtSystemTime.wDayOfWeek = Weekday(m_Date) - 1
udtSystemTime.wHour = Hour(m_Date)
udtSystemTime.wMinute = Minute(m_Date)
udtSystemTime.wSecond = Second(m_Date)
udtSystemTime.wMillisecond s = 0
' convert system time to local time
SystemTimeToFileTime udtSystemTime, udtLocalTime
' convert local time to GMT
LocalFileTimeToFileTime udtLocalTime, udtFileTime
' open the source file to get the filehandle
lngHandle = CreateFile(CDBox.FileName, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
GetFileTime lngHandle, udtCreateTime, udtDummyTime, udtLastWriteTime
CloseHandle lngHandle
'copy the file (will need some smarts here!)
fso.CopyFile CDBox.FileName, "C:\test.tst"
MsgBox "2 (destination after copy): " & fso.GetFile("c:\test.tst") .DateLastA ccessed
'open the destination file to get the filehandle
lngHandle = CreateFile("C:\test.tst", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
' change date/time property of the file
SetFileTime lngHandle, udtCreateTime, udtFileTime, udtLastWriteTime
MsgBox "3 (destination after SetFileTime): " & fso.GetFile("c:\test.tst") .DateLastA ccessed
' close the handle
CloseHandle lngHandle
MsgBox "3 (destination after close): " & fso.GetFile("c:\test.tst") .DateLastA ccessed
End Sub
I feel like I'm getting somewhere now.
Your post led me to do a search for SetFileTime on google, which led me to:
http://www.allapi.net/apilist/apifunction.php?apifunction=SetFileTime
(which has code for setting create, modify, and access time of a file to the current system time)
I've butchered it a bit and it works, sort of . . .
I've got plenty of msgboxes in there to keep track of what is going on:
MSGBOX 1: date of last access of source file
MSGBOX 2: date of last access of destination file after copy
MSGBOX 3: date of last access of destination file after SetFileDate
MSGBOX 4: date of last access of destination file after CloseFile
The date is what I want at MSGBOX 3, but the close "touches" the file and the date is set to the system time.
Help!!
My code:
'=========================
'This project needs a Common Dialog box, named CDBox.
' (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
' and select Microsoft Common Dialog control)
Dim fso As New FileSystemObject
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'KPDTeam@Allapi.net
Dim m_Date As Date, lngHandle As Long
Dim udtFileTime As FILETIME
Dim udtCreateTime As FILETIME
Dim udtLastWriteTime As FILETIME
Dim udtLocalTime As FILETIME
Dim udtDummyTime As FILETIME
Dim udtSystemTime As SYSTEMTIME
'Set the dialog's title
CDBox.DialogTitle = "Choose a file ..."
'Set the dialog's filter
CDBox.Filter = "All Files (*.*)|*.*"
'Show the 'Open File'-dialog
CDBox.ShowOpen
MsgBox "1 (source before copy): " & fso.GetFile(CDBox.FileName
m_Date = fso.GetFile(CDBox.FileName
udtSystemTime.wYear = Year(m_Date)
udtSystemTime.wMonth = Month(m_Date)
udtSystemTime.wDay = Day(m_Date)
udtSystemTime.wDayOfWeek = Weekday(m_Date) - 1
udtSystemTime.wHour = Hour(m_Date)
udtSystemTime.wMinute = Minute(m_Date)
udtSystemTime.wSecond = Second(m_Date)
udtSystemTime.wMillisecond
' convert system time to local time
SystemTimeToFileTime udtSystemTime, udtLocalTime
' convert local time to GMT
LocalFileTimeToFileTime udtLocalTime, udtFileTime
' open the source file to get the filehandle
lngHandle = CreateFile(CDBox.FileName,
GetFileTime lngHandle, udtCreateTime, udtDummyTime, udtLastWriteTime
CloseHandle lngHandle
'copy the file (will need some smarts here!)
fso.CopyFile CDBox.FileName, "C:\test.tst"
MsgBox "2 (destination after copy): " & fso.GetFile("c:\test.tst")
'open the destination file to get the filehandle
lngHandle = CreateFile("C:\test.tst", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
' change date/time property of the file
SetFileTime lngHandle, udtCreateTime, udtFileTime, udtLastWriteTime
MsgBox "3 (destination after SetFileTime): " & fso.GetFile("c:\test.tst")
' close the handle
CloseHandle lngHandle
MsgBox "3 (destination after close): " & fso.GetFile("c:\test.tst")
End Sub
use Xcopy! from dos
ASKER
Sorry for delay, wasn't working for me until I tried (a similar program) on a server with NTFS 2000 partitions (I was running on a FAT32 partition).
Open the help file and search for ntbackup
for details