2

Hey I am trying to work with the EnumerateFiles function, but when I try and run my program it says: error BC30616: Variables 'e' hides a variable in an enclosing block

Could anyone help? its much appreciated!

Imports System.IO

Public Class frmExtractionator

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

        Dim sourceDirectory As String = "F:\CopierFolderforTestDriveCapstone"
        Dim archiveDirectory As String = "F:\FilesExtracted"

        Try
            Dim txtFiles = Directory.EnumerateFiles(sourceDirectory)

            If(Not System.IO.Directory.Exists(archiveDirectory )) Then
                System.IO.Directory.CreateDirectory(archiveDirectory)
            End If

            For Each currentFile As String In txtFiles
                Dim fileName = currentFile.Substring(sourceDirectory.Length + 1)
                File.Move(currentFile, Path.Combine(archiveDirectory, fileName))
            Next
        Catch eT As Exception
            Console.WriteLine(eT.Message)
        End Try

    End Sub
End Class
Cairnarvon
  • 25,981
  • 9
  • 51
  • 65
Clark Gibson
  • 33
  • 2
  • 6

1 Answers1

1

Try this Change

reason Variable : e is used twice

Catch eT As Exception
    Console.WriteLine(eT .Message)
End Try

Where is e already used ?

btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

update: About your Doubt:

 Directory.Move(currentFile, Path.Combine(archiveDirectory, fileName))

i think you are trying to move file not Directory right?

use File.Move instead , remember to create the archiveDirectory

update2: Add this to your code before For Each

If(Not System.IO.Directory.Exists(archiveDirectory )) Then
    System.IO.Directory.CreateDirectory(archiveDirectory )
End If
internals-in
  • 4,798
  • 2
  • 21
  • 38
  • Hey thank you you were right! Just wondering though, every time I hit the button to extract the files and put them in a new folder it doesn't work? – Clark Gibson Mar 25 '13 at 00:20
  • Yes I am new lol, but I will accept your answer. I am really trying to move files inside of a folder if I am doing it right – Clark Gibson Mar 25 '13 at 00:27
  • use File.Move?, remember to create the archiveDirectory – internals-in Mar 25 '13 at 00:28
  • I was thinking that It would create a folder for me and put the files inside of it, but you are saying I need to already have that folder created inside the flash drive? and I am attempting to use the File.Move (I do appreciate your help very much) – Clark Gibson Mar 25 '13 at 00:32
  • it say 'If' must end with endIf should I add it in there? – Clark Gibson Mar 25 '13 at 00:38
  • Okay I tired it, and its not working. I think I messed it all up. Heres what I got...I edited my question.. – Clark Gibson Mar 25 '13 at 00:42
  • waht u mean by "not working", is it not copying? and any exceptions ? then what exception? – internals-in Mar 25 '13 at 00:48
  • Its says the following: Could not find a part of the path 'F:\CopierFolderforTestDriveCapstone'. – Clark Gibson Mar 25 '13 at 00:50
  • hey does F:\CopierFolderforTestDriveCapstone actually exists and it contain files? its your source?then go find F:\CopierFolderforTestDriveCapstone it! – internals-in Mar 25 '13 at 00:52
  • Wait wait, I was wrong I had the folder name wrong in my flash drive, it was successful! Thank you very much man. Now all I need to do is find how I can copy only the recently modified files. – Clark Gibson Mar 25 '13 at 00:53
  • have some reference around http://stackoverflow.com/questions/3668340/get-file-modified-date-in-vb-net – internals-in Mar 25 '13 at 00:56