Loop through files in a folder
Loop through files in a folder
Loop through files in a folder
Loop through files in a folder
Loop through files in a folder
Loop through files in a folder Loop through files in a folder Loop through files in a folder Loop through files in a folder Loop through files in a folder Loop through files in a folder Loop through files in a folder Loop through files in a folder
Loop through files in a folder Loop through files in a folder
Loop through files in a folder
Go Back  Xtreme Visual Basic Talk > > > Loop through files in a folder


Reply
 
Thread Tools Display Modes
  #1  
Old 02-20-2005, 04:30 PM
Ahren Ahren is offline
Regular
 
Join Date: Mar 2003
Posts: 94
Default Loop through files in a folder


I would like to know if there is a way I can loop through the files in a folder, and then copy each of the files. I am trying to make a very simple install program.
Reply With Quote
  #2  
Old 02-21-2005, 05:56 PM
MKoslof's Avatar
MKoslofLoop through files in a folder MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

You can try a recursive search and copy of files like so:

Code:
Private Sub RecursiveCopyFiles( _ ByVal sourceDir As String, _ ByVal destDir As String, _ ByVal fRecursive As Boolean) Dim i As Integer Dim posSep As Integer Dim sDir As String Dim aDirs() As String Dim sFile As String Dim aFiles() As String If Not sourceDir.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()) Then sourceDir &= System.IO.Path.DirectorySeparatorChar End If If Not destDir.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()) Then destDir &= System.IO.Path.DirectorySeparatorChar End If ' Recursive switch to continue looping dir If fRecursive Then aDirs = System.IO.Directory.GetDirectories(sourceDir) For i = 0 To aDirs.GetUpperBound(0) ' Get the position of the last separator in the current path. posSep = aDirs(i).LastIndexOf("\") ' Get the path of the source dir sDir = aDirs(i).Substring((posSep + 1), aDirs(i).Length - (posSep + 1) ' Create the new directory in the destination directory. System.IO.Directory.CreateDirectory(destDir + sDir) 'copy child files RecursiveCopyFiles(aDirs(i), (destDir + sDir), fRecursive) Next End If ' Get the files from the current parent. aFiles = System.IO.Directory.GetFiles(sourceDir) ' Copy all files. For i = 0 To aFiles.GetUpperBound(0) posSep = aFiles(i).LastIndexOf("\") sFile = aFiles(i).Substring((posSep + 1), aFiles(i).Length - (posSep + 1)) System.IO.File.Copy(aFiles(i), destDir + sFile) Next i End Sub
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Loop through files in a folder
Loop through files in a folder
Loop through files in a folder Loop through files in a folder
Loop through files in a folder
Loop through files in a folder
Loop through files in a folder Loop through files in a folder Loop through files in a folder Loop through files in a folder Loop through files in a folder Loop through files in a folder Loop through files in a folder
Loop through files in a folder
Loop through files in a folder
 
Loop through files in a folder
Loop through files in a folder
 
-->