?
Solved

Copy open files

Posted on 2002-07-02
8
Medium Priority
?
153 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
[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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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 143

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 17 hours left to enroll

764 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