any example how to copy files? thanks!

Dani AI

Generated

Quick, practical summary for copying files in VB6 (adds concrete examples to the brief replies above). asked for a simple example; pointed toward scripting, and mentioned a helpful attachment. Below are three common approaches, when to use each, and small, ready-to-run snippets.

Built-in one-liner (simple single-file copy)

On Error GoTo ErrHandler
FileCopy "C:\path\source.txt", "C:\path\dest.txt"
Exit Sub

ErrHandler:
MsgBox "Copy failed: " & Err.Description

Scripting.FileSystemObject (flexible, supports wildcards and folders)

' late binding — no reference needed
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "C:\folder\*.txt", "D:\backup\", True

If you prefer early binding add Project->References->Microsoft Scripting Runtime and declare Dim fso As New Scripting.FileSystemObject.

Windows API (low-level, returns Win32 error codes)

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

If CopyFile("C:\a.txt", "C:\b.txt", 0) = 0 Then
    MsgBox "Copy failed. Error code: " & Err.LastDllError
End If

Quick gotchas and tips

  • FileCopy and FSO require the destination folder to exist; create it first (MkDir or FSO.CreateFolder).
  • Watch file locks, permissions and UNC paths on networks.
  • For large-file progress or resume, read/write in chunks or use shell APIs designed for user feedback.
  • Always catch errors and use full paths to avoid surprising results.

These three patterns cover nearly every VB6 copying need. Choose FileCopy for simplicity, FSO for convenience (wildcards/folders), and the API when you need native error codes or more control.

Recommended Answers

All 2 Replies

All the details that you need is here.

The attachment covers all about copying and pasting of files as well as saving the link to a database.

You are quite lucky that Debasisdas and myself is helping you out like this today, normally we want to see some effort from the poster's side. Please read our posting rules here:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.