Connecting Tech Pros Worldwide Forums | Help | Site Map

How to copy files inside subdirectories in vb6.0

Newbie
 
Join Date: Mar 2007
Location: India
Posts: 13
#1: Mar 21 '07
Hello guys,
I'm working on a code in VB6.0 which involves copying all the files inside a folder to another folder. I have managed to do that but the problem arises when there are subfolders inside the parent folder. I cannot copy the files inside the subfolders.

For eg if my Parent Folder is C:/Anup and it contains 2 files "1.txt","2.txt" and 2 subfolders "C:/Anup/sub1 " and "C:/Anup/sub2 ", I can copy the files 1.txt,2.txt but i cannot copy the files inside sub1,sub1 along with it. Please help me on that.
Urgent help will be greatly appreciated

Newbie
 
Join Date: Mar 2007
Location: India
Posts: 13
#2: Mar 21 '07

re: How to copy files inside subdirectories in vb6.0


I would like to add something to my query. I am working with a tool called as documentum and i need to copy all the files inside a directory (including files inside a subdirectory) into a single documentum cabinet. Hence i cannot use the copyfolder method of FileSystemObject and i have to do it file by file, directory by directory. Any help??
vijaydiwakar's Avatar
Site Addict
 
Join Date: Feb 2007
Posts: 579
#3: Mar 21 '07

re: How to copy files inside subdirectories in vb6.0


Hi,
Try to use Shell Commands
It will defenetly help u
good luck
Newbie
 
Join Date: Mar 2007
Location: India
Posts: 13
#4: Mar 21 '07

re: How to copy files inside subdirectories in vb6.0


Hello vijay,
I have no idea what are shell commands. Could you please tell me a concise method and/or the actual code rather than just giving a vague answer?
vijaydiwakar's Avatar
Site Addict
 
Join Date: Feb 2007
Posts: 579
#5: Mar 21 '07

re: How to copy files inside subdirectories in vb6.0


Quote:

Originally Posted by anupkossambe

Hello vijay,
I have no idea what are shell commands. Could you please tell me a concise method and/or the actual code rather than just giving a vague answer?

try this code
Expand|Select|Wrap|Line Numbers
  1. Dim fSys As New FileSystemObject
  2.  
  3. Private Sub Form_Load()
  4. With fSys
  5. .CopyFolder "C:\temp", "D:\", True
  6. End With
  7. End Sub
  8.  
  9.  
It will copy c:\temp foleder to d:\
here temp folder contains another folder temp1
and it contains temp.txt
Good Luck
Newbie
 
Join Date: Mar 2007
Location: India
Posts: 13
#6: Mar 21 '07

re: How to copy files inside subdirectories in vb6.0


I figured it out anyways . Here is the code for other newbies(like me)

Public Function GetFolders(sStartFolderpath As String) As String
On Error Resume Next
Dim f, fldr As Folder
Set fldr = fs.GetFolder(sStartFolderpath)
GetFolders = fldr.path & vbCrLf
ReDim Preserve subfoldernames(fldr.SubFolders.Count)

If fldr.SubFolders.Count > 0 Then
For Each f In fldr.SubFolders
subfoldernames(foldercount) = f
foldercount = foldercount + 1
GetFolders = GetFolders & GetFolders(f.path)
Next
End If
End Function



THANKS AGAIN VIJAY. Thats the second time u helped me i suppose
Reply