Solved

Copy open files

Posted on 2002-07-02
8
147 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

831 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