Solved

Copy open files

Posted on 2002-07-02
8
146 Views
Last Modified: 2010-05-02
Hi,

I have tried both the FileSystem Object and API to copy files that are open by other programs, (This is a backup app and must do this) but have been unsuccessful with some. Does anyone know a bomb-proof method to achieve this, please.

Thank you.

Regards,
  Tony
0
Comment
Question by:tvtech
8 Comments
 
LVL 6

Expert Comment

by:xSinbad
ID: 7124386
Give this a try;

Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long

Useage;

CopyFile "FileName","NewFileName",False


this should work on open files.

Cheers
Marcus
0
 

Author Comment

by:tvtech
ID: 7124392
Thanks Marcus,

  That is the very same API I mentioned. It does not allow copying of open files on NT, or Server 2000, specifically Microsoft Outlook .PST files. However, it does work on Windows 9x.

Regards,
  Tony
0
 

Author Comment

by:tvtech
ID: 7124401
Thanks Marcus,

  That is the very same API I mentioned. It does not allow copying of open files on NT, or Server 2000, specifically Microsoft Outlook .PST files. However, it does work on Windows 9x.

Regards,
  Tony
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 7125212
Have you tried this method?

Option Explicit

Private Type SHFILEOPSTRUCT
   hwnd As Long
   wFunc As Long
   pFrom As String
   pTo As String
   fFlags As Integer
   fAnyOperationsAborted As Boolean
   hNameMappings As Long
   lpszProgressTitle As String
End Type

Private Const FO_COPY = &H2
Private Const FOF_SIMPLEPROGRESS = &H100
Private Const FOF_NOCONFIRMMKDIR = &H200
Private Const FOF_NOCONFIRMATION = &H10


Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Sub Command1_Click()
    Debug.Print fSHFileCopy("C:\temp\test.txt", "C:\temp\test2.txt")
End Sub

Public Function fSHFileCopy(ByVal strSrc As String, ByVal strDst As String) As Boolean
    Dim fo As SHFILEOPSTRUCT
    Dim lngRes As Integer
   
    fo.pFrom = strSrc
    fo.pTo = strDst
    fo.fFlags = FOF_NOCONFIRMATION Or FOF_NOCONFIRMMKDIR
    fo.wFunc = FO_COPY
    lngRes = SHFileOperation(fo)
    fSHFileCopy = (lngRes = 0)  'return true if zero
   
End Function

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:TomLaw1999
ID: 7125321
Some compression utilities allow you to backup an open file. I use Zlib for this. It's free and available either as a DLL or OCX for use with vb.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7126003
PaulHews, your method doesn't work for pst files that Outlook currently has openend :-(
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7971211
Hi tvtech,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

tvtech, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8018736
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 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

27 Experts available now in Live!

Get 1:1 Help Now