Answered by:
file copying from different locations to different locations.

Question
-
HelloI am new to this forum.I am trying to copy files from different folder locations to different folder locations. For that I have written codes as follows:But it do not work.......shows error in 4th For loop statement. Please help!Many thanksLijo===============Public Sub copyFiles()' On Error Resume NextDim FSO As Scripting.FileSystemObjectSet FSO = CreateObject("Scripting.FileSystemObject")Dim mainDestFldr As folderDim subDestFldr As folderDim sub2DestFldr As folderDim sFldr As folderDim FirstSubFldr As folderDim SecondSubFldr As folderDim ThirdSubFldr As folderDim fil As folderDim sPath As StringsPath = "G:\01 - CERTIFICATE"Set mainDestFldr = FSO.GetFolder("G:\TO HANDOVER TO COMPANY\Train 5 MAP\")For Each FirstSubFldr In mainDestFldr.SubFoldersSet subDestFldr = FSO.GetFolder(FirstSubFldr)For Each SecondSubFldr In subDestFldr.SubFoldersSet sub2DestFldr = FSO.GetFolder(SecondSubFldr)For Each ThirdSubFldr In sub2DestFldr.SubFolderssPath = sPath & Trim(Mid(SecondSubFldr, InStr(32, SecondSubFldr, "\"), 20))Set sFldr = FSO.GetFolder(sPath)For Each fil In sFldrIf fil Like SecondSubFldr & "*.*" And ThirdSubFldr.Path = "DISCIPLINE COMPLETIONS CERTIFICATE" ThenMsgBox filFSO.copyFile fil, ThirdSubFldr.PathName fil As fil & "_done"ElseIf fil Like "RFC*.*" And ThirdSubFldr.Path = "RFC" ThenMsgBox filFSO.copyFile fil, ThirdSubFldr.PathElseIf fil Like "SMCC*.*" And ThirdSubFldr.Path = "SMCC" ThenMsgBox filFSO.copyFile fil, ThirdSubFldr.PathEnd IfNext filNext ThirdSubFldrNext SecondSubFldrNext FirstSubFldrMsgBox "Completed Successfully!!!"Set sFldr = NothingSet mainDestFldr = NothingSet subDestFldr = NothingSet FirstSubFldr = NothingSet SecondSubFldr = NothingSet ThirdSubFldr = NothingEnd Sub=======================
- Moved by Jeff Shan Tuesday, December 1, 2009 2:31 AM vb6 question (From:Visual Basic General)
Sunday, November 29, 2009 12:26 PM
Answers
-
Use These Method
Dim FileToCopy As String Dim NewCopy As String FileToCopy = "C:\test.txt" NewCopy = "C:\NewTest.txt" If System.IO.File.Exists(FileToCopy) = True Then System.IO.File.Copy(FileToCopy, NewCopy) MsgBox("File Copied") End If
and
If (Directory.Exists(sourcePath)) Then For Each fName As String In Directory.GetFiles(sourcePath) If File.Exists(fName) Then Dim dFile As String = String.Empty dFile = Path.GetFileName(fName) Dim dFilePath As String = String.Empty dFilePath = DestinationPath + dFile File.Copy(fName, dFilePath, True) End If Next End If
Adopt To Here
http://www.eggheadcafe.com/tutorials/aspnet/75dc1a36-1493-4ae7-b71c-9af1e11b44da/copy-delete-and-move-fil.aspx
www.shariqdon.media.officelive.com- Edited by Shariq Ayaz Sunday, November 29, 2009 12:45 PM
- Marked as answer by Jeff Shan Tuesday, December 1, 2009 2:31 AM
Sunday, November 29, 2009 12:30 PM -
But i m Alway Use This For Copy File
Dim webc As New System.Net.WebClient() webc.DownloadFile("c:\test.txt", "d:\test.txt")
This is Perfect Work For me
www.shariqdon.media.officelive.com- Marked as answer by Jeff Shan Tuesday, December 1, 2009 2:31 AM
Sunday, November 29, 2009 12:44 PM
All replies
-
Use These Method
Dim FileToCopy As String Dim NewCopy As String FileToCopy = "C:\test.txt" NewCopy = "C:\NewTest.txt" If System.IO.File.Exists(FileToCopy) = True Then System.IO.File.Copy(FileToCopy, NewCopy) MsgBox("File Copied") End If
and
If (Directory.Exists(sourcePath)) Then For Each fName As String In Directory.GetFiles(sourcePath) If File.Exists(fName) Then Dim dFile As String = String.Empty dFile = Path.GetFileName(fName) Dim dFilePath As String = String.Empty dFilePath = DestinationPath + dFile File.Copy(fName, dFilePath, True) End If Next End If
Adopt To Here
http://www.eggheadcafe.com/tutorials/aspnet/75dc1a36-1493-4ae7-b71c-9af1e11b44da/copy-delete-and-move-fil.aspx
www.shariqdon.media.officelive.com- Edited by Shariq Ayaz Sunday, November 29, 2009 12:45 PM
- Marked as answer by Jeff Shan Tuesday, December 1, 2009 2:31 AM
Sunday, November 29, 2009 12:30 PM -
But i m Alway Use This For Copy File
Dim webc As New System.Net.WebClient() webc.DownloadFile("c:\test.txt", "d:\test.txt")
This is Perfect Work For me
www.shariqdon.media.officelive.com- Marked as answer by Jeff Shan Tuesday, December 1, 2009 2:31 AM
Sunday, November 29, 2009 12:44 PM -
Thanks for your quick reply.I tried using the above code. But still not able to do it.I have source folder say, "G:\x" with 2 level subfolders and from the 2nd level, I need to access files.Then, the destination folder is like "G:\a\b" with 3 level subfolders.Here 1st level subfolder of source need to be equal to 1st level subfolder of destination and,2nd level subfolder of source need to be equal to 2nd level subfolder of destination.Finally after checking some conditions, the files come under 2nd level subfolder of source need to copy to 3rd level subfolder of destination.I am not much familiar with the given codes. Is there any reference to add? For, it do not accept the variable declarations. So I gave it seperately.Here VB part comes under MS Access. Please advice.Thank you so mcuh for the support.Sunday, November 29, 2009 1:28 PM
-
Just A Question Did you Use VB.6 ?
www.shariqdon.media.officelive.comSunday, November 29, 2009 1:43 PM -
Yes
:-)
This forum supports Visual Basic .NET versions only (7, 8, 9, 10), so, your Visual Basic 6 question is an off-topic here and this isn't the best place to ask it, here is a list of forums, newsgroups, resources and sites, to get an answer about your question :
- Visual Basic 6 Newgroups
- Visual Basic 6.0 on MSDN Library
- MSDN Visual Basic 6.0 Resource Center
- VB City
- VB-Helper
- VB Forums
- CodeGuru
- Code Project
- Planet Source Code
- Visual Basic Interop and Upgrade (Update VB6 codes to .NET)
Success
Cor- Proposed as answer by Shariq Ayaz Sunday, November 29, 2009 3:06 PM
Sunday, November 29, 2009 2:57 PM -
Oh....sorry. I use VB 6.5.Thanks for the suggestion. I will move to suitable groupThanks againMonday, November 30, 2009 4:00 AM