Solved

Copy open files

Posted on 2002-07-02
8
145 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 4

Expert Comment

by:TomLaw1999
Comment Utility
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]
Comment Utility
PaulHews, your method doesn't work for pst files that Outlook currently has openend :-(
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

743 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

16 Experts available now in Live!

Get 1:1 Help Now