Advertisement

05.13.2008 at 07:36AM PDT, ID: 23397951
[x]
Attachment Details

Copy files from arraylist

Asked by judsonhh in .NET, Microsoft Visual Basic.Net, Microsoft Visual C#.Net

Tags: Arraylist, file.copy

I'm attempting to copy some files that I  have in an arraylist to another directory, making the directory if it does not exist and overwritting existing files.  I don't know how to get the files from the list.

The array is built in the "Button4.click" Sub as "filelist". It contains the filepaths from the rest of the class.

Any help would be greatly appriciated.

the "TIMER2" is the same as "button4"Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
Imports System.IO
 
Public Class Form1
 
    '' select source 1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If FolderBrowserDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            Label1.Text = FolderBrowserDialog.SelectedPath
        End If
    End Sub
 
    ''' select source 2
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If FolderBrowserDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            Label2.Text = FolderBrowserDialog.SelectedPath
        End If
    End Sub
 
    ''' select source 3
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If FolderBrowserDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            Label3.Text = FolderBrowserDialog.SelectedPath
        End If
    End Sub
    ''' load timers
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Timer2.Enabled = True
        REM TextBox1.Text = Format(TimeOfDay, "Long Time")
    End Sub
    ''  display clock in program
    Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
        REM Me.Text = TimeOfDay & "      As Run Process"
        Label4.Text = CStr(TimeOfDay)
    End Sub
    '' run action at displayed time
    Private Sub Timer2_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer2.Tick
        If TextBox1.Text = Label4.Text Then
            Dim fldrs As ArrayList = GetFolders(Label1.Text)
            Dim i As Integer
            For i = 0 To (fldrs.Count - 1)
                MessageBox.Show(GetNewestFile(fldrs(i), 150, True))
            Next
        End If
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim fldrs As ArrayList = GetFolders(Label1.Text)
        Dim i As Integer
        Dim FileList As New ArrayList
        For i = 0 To (fldrs.Count - 1)
            FileList.Add(GetNewestFile(fldrs(i), 150, True))
        Next
    End Sub
    Private Function GetFolders(ByVal path As String) As ArrayList
        Dim categories() As String = Directory.GetDirectories(Label1.Text)
        Dim i As Integer
        Dim al As New ArrayList
        For i = 0 To categories.Length - 1
            al.Add(categories(i))
        Next
        Return (al)
    End Function
    ''' <summary>
    ''' Get the name of the file in the specified folder that is the newest over specified size.
    ''' </summary>
    ''' <param name="folderPath">The full path to the folder we want to search</param>
    ''' <param name="minSizeKb">The size (in kilobyes, 1024 bytes) the file must be in order to be considered.</param>
    ''' <param name="includeSubFolders">search subfolders as well</param>
    ''' <returns>Full path to newest file</returns>
    ''' <remarks>Uses last modified date, not created date</remarks>
    Public Function GetNewestFile(ByVal folderPath As String, ByVal minSizeKb As Long, ByVal includeSubFolders As Boolean) As String
 
        Dim latestFileDate As Date = New Date(1901, 1, 1)
        Dim latestFilePath As String = ""
        Dim di As New DirectoryInfo(folderPath)
        If di.Exists Then   ' continue if directory exists
            ' search the current folder first
            searchFolder(di, minSizeKb, includeSubFolders, latestFileDate, latestFilePath)
            If includeSubFolders Then       ' search subfolders if required
                Dim subDirs As DirectoryInfo() = di.GetDirectories()
                For Each subdi In subDirs
                    searchFolder(subdi, minSizeKb, includeSubFolders, latestFileDate, latestFilePath)
                Next
            End If
        End If ' If di.Exists then
        Return latestFilePath
    End Function
    ''' <summary>
    ''' Helper function called recursively for subdirectories.  Do not call this function directly, call 'GetNewestFile'
    ''' </summary>
    ''' <param name="di"></param>
    ''' <param name="minSizeKb"></param>
    ''' <param name="includeSubFolders"></param>
    ''' <param name="latestFileDate">used for returning matches in subdirectories</param>
    ''' <param name="latestFilePath">used for returning matches in subdirectories</param>
    ''' <remarks></remarks>
    Private Sub searchFolder(ByVal di As DirectoryInfo, ByVal minSizeKb As Long, ByVal includeSubFolders As Boolean, _
                                  ByRef latestFileDate As Date, ByRef latestFilePath As String)
        Const KBSIZE As Long = 1024
        Dim fi As FileInfo() = di.GetFiles()        ' get list of all files in directory
        For i = fi.GetLowerBound(0) To fi.GetUpperBound(0)
            If (fi(i).Length / KBSIZE) > minSizeKb Then     ' make sure file meets min size requirement
                If fi(i).LastWriteTimeUtc > latestFileDate Then ' found newer file, save it
                    latestFileDate = fi(i).LastWriteTimeUtc
                    latestFilePath = fi(i).FullName
                End If
            End If
        Next
        If includeSubFolders Then
            Dim subDirs As DirectoryInfo() = di.GetDirectories()
            For Each subdi In subDirs
                searchFolder(subdi, minSizeKb, includeSubFolders, latestFileDate, latestFilePath)
            Next
        End If
    End Sub
End Class
[+][-]05.13.2008 at 07:49AM PDT, ID: 21555597

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 07:53AM PDT, ID: 21555645

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 07:55AM PDT, ID: 21555655

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 08:00AM PDT, ID: 21555715

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 08:01AM PDT, ID: 21555723

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 08:12AM PDT, ID: 21555832

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 10:23AM PDT, ID: 21557237

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 10:51AM PDT, ID: 21557482

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 06:36AM PDT, ID: 21563982

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 07:03AM PDT, ID: 21564289

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 07:09AM PDT, ID: 21564366

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 08:20AM PDT, ID: 21565175

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 09:29AM PDT, ID: 21565931

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 09:54AM PDT, ID: 21566222

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 10:04AM PDT, ID: 21566325

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET, Microsoft Visual Basic.Net, Microsoft Visual C#.Net
Tags: Arraylist, file.copy
Sign Up Now!
Solution Provided By: jcoehoorn
Participating Experts: 3
Solution Grade: B
 
 
[+][-]05.14.2008 at 12:08PM PDT, ID: 21567629

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 01:31PM PDT, ID: 21568387

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906