VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



CopyFileAny

by Mike Owens (2 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

This code allows you to copy any file, including your application to another destination at runtime.
Note: This code has only been tested on Windows 98 using Visual Basic 6.0

Inputs
Input file, output file
Assumes
Note: This sub is only useful for copying inaccessable files. For regular files, the "FileCopy" sub should be called. An example of use would be to make your exe copy itself somewhere else while running.
Code Returns
Returns 1 on success, 0 on error.

Rate CopyFileAny

Public Function CopyFileAny(currentFilename As String, newFilename As String)
Dim a%, buffer%, temp$, fRead&, fSize&, b%
On Error GoTo ErrHan:
a = FreeFile
buffer = 4048
 Open currentFilename For Binary Access Read As a
 b = FreeFile
 Open newFilename For Binary Access Write As b
 fSize = FileLen(currentFilename)
 
 While fRead < fSize
 DoEvents
 If buffer > (fSize - fRead) Then buffer = (fSize - fRead)
 temp = Space(buffer)
 Get a, , temp
 Put b, , temp
 fRead = fRead + buffer
 Wend
 Close b
 Close a
CopyFileAny=1
Exit Function
ErrHan:
CopyFileAny=0
End Function

Download this snippet    Add to My Saved Code

CopyFileAny Comments

No comments have been posted about CopyFileAny. Why not be the first to post a comment about CopyFileAny.

Post your comment

Subject:
Message:
0/1000 characters