?
Solved

File migration

Posted on 2002-06-19
7
Medium Priority
?
294 Views
Last Modified: 2013-12-23
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!
0
Comment
Question by:nedrub
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 79

Expert Comment

by:lrmoore
ID: 7096810
try using ntbackup, copy type backup...

Open the help file and search for ntbackup
for details
0
 

Author Comment

by:nedrub
ID: 7097035
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.
0
 

Author Comment

by:nedrub
ID: 7097209
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.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 28

Accepted Solution

by:
vinnyd79 earned 400 total points
ID: 7099166
Have you tried to do it in VB without using FSO?

Option Explicit
Private Type FILETIME
     dwLowDate  As Long
     dwHighDate 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
     wMillisecs As Integer
 End Type
 
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const GENERIC_WRITE = &H40000000
 
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 LocalFileTimeToFileTime Lib _
     "kernel32" (lpLocalFileTime As FILETIME, _
      lpFileTime As FILETIME) As Long

Private Declare Function SetFileTime Lib "kernel32" _
   (ByVal hFile As Long, ByVal MullP As Long, _
    ByVal NullP2 As Long, 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

Public Function SetFileDateTime(ByVal FileName As String, _
  ByVal TheDate As String) As Boolean
'************************************************
'PURPOSE:    Set File Date (and optionally time)
'            for a given file)
         
'PARAMETERS: TheDate -- Date to Set File's Modified Date/Time
'            FileName -- The File Name

'Returns:    True if successful, false otherwise
'************************************************
If Dir(FileName) = "" Then Exit Function
If Not IsDate(TheDate) Then Exit Function

Dim lFileHnd As Long
Dim lRet As Long

Dim typFileTime As FILETIME
Dim typLocalTime As FILETIME
Dim typSystemTime As SYSTEMTIME

With typSystemTime
    .wYear = Year(TheDate)
    .wMonth = Month(TheDate)
    .wDay = Day(TheDate)
    .wDayOfWeek = Weekday(TheDate) - 1
    .wHour = Hour(TheDate)
    .wMinute = Minute(TheDate)
    .wSecond = Second(TheDate)
End With

lRet = SystemTimeToFileTime(typSystemTime, typLocalTime)
lRet = LocalFileTimeToFileTime(typLocalTime, typFileTime)

lFileHnd = CreateFile(FileName, GENERIC_WRITE, _
    FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, _
    OPEN_EXISTING, 0, 0)
   
lRet = SetFileTime(lFileHnd, ByVal 0&, ByVal 0&, _
         typFileTime)

CloseHandle lFileHnd
SetFileDateTime = lRet > 0

End Function

' usage
Private Sub Command1_Click()
Dim odate
odate = "06/01/01"
SetFileDateTime "D:\Somefile.txt", odate
End Sub
0
 

Author Comment

by:nedrub
ID: 7099385
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).DateLastAccessed
   
    m_Date = fso.GetFile(CDBox.FileName).DateLastAccessed
   
    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.wMilliseconds = 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").DateLastAccessed
   
    '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").DateLastAccessed
   
    ' close the handle
    CloseHandle lngHandle

MsgBox "3 (destination after close): " & fso.GetFile("c:\test.tst").DateLastAccessed

End Sub
 


 



0
 

Expert Comment

by:impoole
ID: 7107588
use Xcopy! from dos
0
 

Author Comment

by:nedrub
ID: 7108904
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).
0

Featured Post

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever set up your wireless router at home or in the office to find that you little pop-up bubble in the bottom right-hand corner of Windows read "IP Conflict - One of more computers on the network have been assigned the following IP address"…
I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question