Solved

File migration

Posted on 2002-06-19
7
267 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
7 Comments
 
LVL 79

Expert Comment

by:lrmoore
Comment Utility
try using ntbackup, copy type backup...

Open the help file and search for ntbackup
for details
0
 

Author Comment

by:nedrub
Comment Utility
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
Comment Utility
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 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
use Xcopy! from dos
0
 

Author Comment

by:nedrub
Comment Utility
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

New My Cloud Pro Series - organize everything!

With space to keep virtually everything, the My Cloud Pro Series offers your team the network storage to edit, save and share production files from anywhere with an internet connection. Compatible with both Mac and PC, you're able to protect your content regardless of OS.

Join & Write a Comment

A brief overview to explain gateways, default gateways and static routes OR NO - you CANNOT have two default gateways on the same server, PC or other Windows-based network device. In simple terms a gateway is formed when a computer such as a serv…
Downtime reduced, data recovered by utilizing an Experts Exchange Business Account Challenge The United States Marine Corps employs more than 200,000 active-duty Marines with operations in four continents, all requiring complex networking system…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now