Solved

Copy open files

Posted on 2002-07-02
8
149 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

735 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