Copying multiple files from an array ???
Copying multiple files from an array ???
Copying multiple files from an array ???
Copying multiple files from an array ???
Copying multiple files from an array ???
Copying multiple files from an array ??? Copying multiple files from an array ??? Copying multiple files from an array ??? Copying multiple files from an array ??? Copying multiple files from an array ??? Copying multiple files from an array ??? Copying multiple files from an array ??? Copying multiple files from an array ???
Copying multiple files from an array ??? Copying multiple files from an array ???
Copying multiple files from an array ???
Go Back  Xtreme Visual Basic Talk > > > Copying multiple files from an array ???


Reply
 
Thread Tools Display Modes
  #1  
Old 03-28-2011, 06:18 PM
leviticus leviticus is offline
Newcomer
 
Join Date: Mar 2011
Posts: 5
Default Copying multiple files from an array ???


I've still got quite a bit to learn about visual basic; I'm hoping there's an easy solution to this problem.

I'm trying to copy multiple files from a directory, put them into an array, then copy just the 30 newest files(I haven't coded the 30 newest loop yet).

I added a list box to the following code just to ensure the all the files are storing into the array properly... they are.

When it try's to copy, it renames the first file to .log, then tells me that the .log file already exist. How do I get it to copy and keep the source file name in the destination folder Eventually I'll loop this and grab only 30 of the files.

Here's the code I'm playing with:

Private Sub transferButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles transferButton.Click


'ensure the source directory exist
If Directory.Exists("D:\Evolis_Test1") = False Then
MessageBox.Show("Source directory doesn't exist", "D:\Evolis_Test1", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

'put files into the "foundFile" array
For Each foundFile As String In My.Computer.FileSystem.GetFiles("D:\Evolis_Test1", _
'FileIO.SearchOption.SearchTopLevelOnly, "*.log")

'display files in a list box
ListBox1.Items.Add(foundFile)

'copy files from array to destination folder My.Computer.FileSystem.CopyFile(foundFile, "D:\Evolis_Test2\.log")

Next
End Sub

I'm using VB 2008... any help would be great!!!
Reply With Quote
  #2  
Old 03-28-2011, 06:41 PM
PlausiblyDamp's Avatar
PlausiblyDampCopying multiple files from an array ??? PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

The line of code
Code:
My.Computer.FileSystem.CopyFile(foundFile, "D:\Evolis_Test2\.log")
has the destination filename set as ".log" - every file you copy will simply be using the same name.

If you want to get the original filename from the foundFile string then System.IO.Path should be a good starting point.
You would then need to build a destination path from the target folder and the file name.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 04-01-2011, 11:24 AM
leviticus leviticus is offline
Newcomer
 
Join Date: Mar 2011
Posts: 5
Default

I tried System.IO.Path, but could not get the files to copy. I eventually got the results to cross using the following syntax:


For Each foundFile As String In My.Computer.FileSystem.GetFiles(srcPath, _
FileIO.SearchOption.SearchTopLevelOnly, "*.log")

Dim fileName As String = My.Computer.FileSystem.GetName(foundFile)
Dim destPath As String = "D:\Evolis_Test2\" & fileName

ListBox1.Items.Add(foundFile)
ListBox2.Items.Add(fileName)

My.Computer.FileSystem.CopyFile(foundFile, destPath, True)

Next

Now, I need to figure out how to loop it 30 times. There's over 900 files in my srcFolder, but I only want to copy the first 30. I've tried placing a couple loops, but have not cracked it yet. Perhaps I can modify the wildCard parameter???

Any ideas?
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
Copying multiple files from an array ???
Copying multiple files from an array ???
Copying multiple files from an array ??? Copying multiple files from an array ???
Copying multiple files from an array ???
Copying multiple files from an array ???
Copying multiple files from an array ??? Copying multiple files from an array ??? Copying multiple files from an array ??? Copying multiple files from an array ??? Copying multiple files from an array ??? Copying multiple files from an array ??? Copying multiple files from an array ???
Copying multiple files from an array ???
Copying multiple files from an array ???
 
Copying multiple files from an array ???
Copying multiple files from an array ???
 
-->