| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 631 人关注过本帖
标题:VB.net如何做到复制所有同名的文件从一文件夹到另一文件夹
只看楼主 加入收藏
zhangzhen
Rank: 2
等 级:论坛游民
帖 子:92
专家分:27
注 册:2011-3-4
结帖率:100%
收藏
已结贴  问题点数:0 回复次数:2 
VB.net如何做到复制所有同名的文件从一文件夹到另一文件夹
比如说复制所有叫zz的不管什么后缀的文件都复制到指定文件夹?
搜索更多相关主题的帖子: 文件夹 
2011-07-25 20:46
haigecnpeng
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:2
帖 子:261
专家分:510
注 册:2008-10-6
收藏
得分:0 
理论上是可以的,不过懒得写了,搜下吧,
大概思路是先在制定的范围内搜索文件,这个例子在很多地方有
然后,filecopy就行了

都说到了.net年代,VB与C#都是一样的!
但为什么招聘的都是C#呢?
2011-07-28 19:43
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:5 
练习了一下,是这样吗?用VB6的思路去写的~
顺道问一下~这样写好像FileListBox1的反应不是很灵敏~
这是为何?

程序代码:
Option Explicit On

Public Class Form1

    Dim FileList() As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim TempString As String, FilePath As String, SmailarFile As String, Temp() As String, Target As String
        Dim i As Short, j As Object

        ReDim FileList(0)

        If TextBox1.Text <> "" Then
            Target = Trim(InputBox("The Target File Path is ..."))
            If Target <> "" Then

                Target = IIf(Mid(Target, Len(Target), 1) = "\", Target, Target & "\")
                TempString = Trim(TextBox1.Text) : ToolTip1.SetToolTip(TextBox1, TempString)

                If InStr(TempString, ":") <> 0 And InStr(TempString, "\") <> 0 And InStr(TempString, ".") <> 0 Then

                    Temp = Split(TempString, "\")
                    DriveListBox1.Drive = Temp(0)
                    If UBound(Temp) > 2 Then
                        For i = 0 To UBound(Temp) - 1
                            FilePath = FilePath & Temp(i) & "\"
                        Next i
                        DirListBox1.Path = FilePath
                    Else
                        DirListBox1.Path = Temp(0) & "\"
                    End If

                    SmailarFile = Mid(Temp(UBound(Temp)), 1, InStr(Temp(UBound(Temp)), ".") - 1)
                    FileListBox1.Pattern = "*.*"
                    FileListBox1.Path = FilePath
                    i = 0 : ListBox1.Items.Clear()
                    For Each j In FileListBox1.Items
                        If InStr(j, SmailarFile) <> 0 Then
                            ReDim Preserve FileList(i)
                            FileList(i) = FilePath & j
                            ListBox1.Items.Add(j)
                            i += 1
                        End If
                    Next j

                    For i = 0 To UBound(FileList)
                        FileCopy(FileList(i), Target & Mid(FileList(i), InStrRev(FileList(i), "\") + 1))
                    Next i

                    'MessageBox.Show(Join(FileList, vbNewLine))

                Else
                    MessageBox.Show("Input File Path Format Error !", "ERROR")
                    TextBox1.Text = "" : ListBox1.Items.Clear()
                End If
            Else
                MessageBox.Show("No Target Path !", "ERROR")
            End If
        Else
            MessageBox.Show("No Data !", "ERROR")
        End If

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Text = "" : ListBox1.Items.Clear()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Application.Exit()
    End Sub

    Private Sub DriveListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveListBox1.SelectedIndexChanged
        DirListBox1.Path = DriveListBox1.Drive
        FileListBox1.Path = DirListBox1.Path
    End Sub

    Private Sub DirListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DirListBox1.SelectedIndexChanged
        FileListBox1.Items.Clear()
        FileListBox1.Path = DirListBox1.Path
    End Sub

End Class

不要選我當版主
2011-07-29 01:09
快速回复:VB.net如何做到复制所有同名的文件从一文件夹到另一文件夹
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.048959 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved