Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A program to copy files in drive A: (Second Post) 1

Status
Not open for further replies.

siearo

MIS
Aug 21, 2002
15
LK
The below question has been posted before but got no satisfactory reply. I would be grateful if anyone can help.

"I want to execute a program to copy all files in drive a: in to C:\temp\ folder without getting halted if there is no disk in drive a:. No message should be displayed. i.e. all files in the floppy should be copied without the user knowing.
Can anybody please give me the source code of a program in Visual Basic to do this job."

The light flashing on the drive is not a problem.
 
Hi,

It would have been better if you continued your first post so others will know how their suggestions went. Anyway, here's a simple code using the FileSystemObject
'--------------------------------------------------------------------
Private Sub SilentCopy()
Dim fso As New FileSystemObject
Dim oFolder As Folder
Dim oFile As File
Const strSourcePath = "A:\"
Const strTargetPath = "C:\TEMP\"

On Error Resume Next
Set oFolder = fso.GetFolder(strSourcePath)
For Each oFile In oFolder.Files
fso.CopyFile strSourcePath & oFile.Name, _
strTargetPath & oFile.Name, _
True
'DoEvents will make this procedure act
'like a background task!
DoEvents
Next

Set fso = Nothing
Set oFolder = Nothing
End Sub


Regards
 
siearo
Stop posting multiple threads on the same topic. Stick the the original thread until you get a satifactory answer. It will not help to to start an new thread - only add to the confusion. Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Is this the same problem as your original post thread222-353604 (as well as being a re-post of thread222-354281)?

Did alphanytz's solution work for you or do you need more help?
Must think of a witty signature
 
Thanks guys. I'm new here and forgive me for posting on more than one thread. I'll check this code. Thanks again.
 
Q1-
Dear alphanytz
How to link this function to the main program? since there is a compile error on this account -eg. fso As New FileSystemObject ( user defined type not specified.)
even though this portion compiles well it does not perform any operation on the computer.
Q2-
By the way, I got the below mentioned code,
Private Sub Form_Load()
On Error Resume Next
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.GetFile("a:\test.txt")
MyFile.Copy ("c:\temp\test.txt")
End

End Sub

This copies only the specified file (test.txt). How to use wild cards (*,?) instead?

p.s.-I have to thank DarenNM for defending me in my absence in "thread222-354281" and he was right.
 
siearo
On Q1: Have you done setting reference to "Microsoft Scripting Runtime"? (Projects/References)
DLL filename: C:\WINDOWS\SYSTEM\SCRRUN.DLL
FileSystemObject is just one of its classes.
You use (or "call") the procedure simply by using the Call statement, or just the procedure name, as in...
Code:
Private Sub Command1_Click()
    Call SilentCopy
End Sub
- or -
Code:
Private Sub Command1_Click()
    SilentCopy
End Sub

"I want to execute a program to copy all files in drive a: in to C:\temp\ folder without getting halted if there is no disk in drive a:. No message should be displayed. i.e. all files in the floppy should be copied without the user knowing.
Can anybody please give me the source code of a program in Visual Basic to do this job."


The code copies ALL files from Drive A: to C:\TEMP

[peace]
 
alphanytz
It works fine. Thank you v much. I appreciate it.
regards.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top