0

所以这是我必须创建的一个应用程序,它将文件从一个目录移动到另一个目录,两个目录都由用户指定。这似乎很容易,但问题是必须搜索数百万个文件。这些文件都以 8 位数字命名,例如“98938495.crt”。所有这些文件所在的目录有多个文件夹。主文件夹中的这些文件夹以文件夹中所有文件的前两位数字命名。然后在该文件夹中大约有十个压缩文件夹,每个文件夹包含 100,000 个文件。这些文件夹的名称是文件的最小和最大名称。例如,我进入主文件夹,然后单击“90xx”文件夹。其中有 10 个压缩文件夹,以文件的最小和最大名称命名,像“90000000_90099999.zip”。该 zip 文件夹包含 100000 个文件。现在,这个应用程序应该找到用户输入的所有文件,然后将它们移动到用户指定的文件夹中。到目前为止,我已经在下面发布了我的代码,非常感谢任何帮助!

仅供参考:STID 是文件的名称。

应用程序的 GUI

编辑:我意识到没有办法回答这个问题,因为真的没有问题,只是一个坏掉的应用程序。基本上,我如何搜索目录中的项目,然后将它们复制到新目录中?

Imports System
Imports System.IO


Public Class CertFinder

Private Sub SourceDirectoryTB_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SourceDirectoryTB.TextChanged

End Sub

Private Sub DestinationDirectoryTB_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DestinationDirectoryTB.TextChanged

End Sub

Private Sub SearchTB_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchTB.TextChanged


End Sub

Private Sub SourceButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SourceButton.Click

    Dim fbd As New FolderBrowserDialog
    fbd.RootFolder = Environment.SpecialFolder.MyComputer
    If fbd.ShowDialog = DialogResult.OK Then
        SourceDirectoryTB.Text = fbd.SelectedPath

    End If

End Sub

Private Sub DestinationButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DestinationButton.Click

    Dim fbd As New FolderBrowserDialog
    fbd.RootFolder = Environment.SpecialFolder.MyComputer
    If fbd.ShowDialog = DialogResult.OK Then
        DestinationDirectoryTB.Text = fbd.SelectedPath
    End If

End Sub




Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click

    'Array of stids
    Dim stidsToFind As String()

    'get text in the searchTB textbox
    Dim searchTBText As String = Me.SearchTB.Text.Trim()

    'splits stids into seperate lines
    stidsToFind = searchTBText.Split(vbCrLf)

    'gets text from source directory text box
    Dim sourceDirectory As String = Me.SourceDirectoryTB.Text.Trim()

    'gets text from destination directory text box
    Dim destinationDirectory As String = Me.DestinationDirectoryTB.Text.Trim()

    Dim fullPathToFile As String = sourceDirectory

    'Go through each stid in the search text box and continue if nothing
    For Each stidToFind As String In stidsToFind

        If String.IsNullOrWhiteSpace(stidToFind) Then
            Continue For
        End If


        'Find the first two digits of the stid
        Dim firstTwoDigitsOfSTID As String = stidToFind.Substring(0, 2)

        'In the specified directory, find the folder with the first two digits and "xx"
        fullPathToFile = fullPathToFile & "\" & firstTwoDigitsOfSTID & "xx"



        Dim allFileNames As String() = Nothing
        allFileNames = Directory.GetFiles(sourceDirectory, "*.crt*", SearchOption.AllDirectories)

    Next

    '-------------------------------------------------------------------------------

    Try
        If File.Exists(fullPathToFile) = False Then
            Dim FS As FileStream = File.Create(fullPathToFile)
            FS.Close()
        End If


        File.Move(fullPathToFile, destinationDirectory)
        Console.WriteLine("{0} moved to {1}", fullPathToFile, destinationDirectory)

    Catch ex As Exception

        MessageBox.Show("File does not exist")

    End Try




    Dim sc As New Shell32.Shell()

    'Declare the folder where the files will be extracted
    Dim output As Shell32.Folder = sc.NameSpace(destinationDirectory)
    'Declare your input zip file as folder  .
    Dim input As Shell32.Folder = sc.NameSpace(stidsToFind)
    'Extract the files from the zip file using the CopyHere command .
    output.CopyHere(input.Items, 4)

    '-------------------------------------------------------------------------------



    ' 1. Get the names of each .zip file in the folder.
    ' 2. Assume that the .zip files are named as such <minimum STID>_<maximum STID>.zip
    ' 3. For each .zip file name, get the Minimum STID and Maximum STID values.
    ' 4. Check the range of 'stidToFind' against the STID ranges of each .zip file.
    ' 5. Once the .zip file is located, 
    '   a. Copy the .zip file to the local computer OR
    '   b. Just leave it where it is.
    ' 6. Unzip the file.
    ' 7. Create the full file name path. ../<stidToFind>.crt
    ' 8. Copy the file to the destination directory.
    ' 9. Delete the unzipped folder
    ' 10. Delete the .zip file (IF you've copied it to your local computer).








End Sub

结束类

4

1 回答 1

0
  1. 作为对 .ZIP 解包的回答,请使用 System.IO.Packaging(更多信息可在CodeProject - Zip Files Easy中找到)
  2. 您不认为使用数据库更容易存储这些数据吗?
于 2013-08-11T00:20:28.133 回答