By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,800 Members | 1,300 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,800 IT Pros & Developers. It's quick & easy.

How to copy files inside subdirectories in vb6.0

P: 13
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
Mar 21 '07 #1
Share this Question
Share on Google+
5 Replies


P: 13
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??
Mar 21 '07 #2

vijaydiwakar
100+
P: 579
Hi,
Try to use Shell Commands
It will defenetly help u
good luck
Mar 21 '07 #3

P: 13
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?
Mar 21 '07 #4

vijaydiwakar
100+
P: 579
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
Mar 21 '07 #5

P: 13
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
Mar 21 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.