| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 581 人关注过本帖
标题:如何批量读取文件夹中指定文件的内容??
只看楼主 加入收藏
菜鸟新上路
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2008-9-15
结帖率:60%
收藏
已结贴  问题点数:20 回复次数:1 
如何批量读取文件夹中指定文件的内容??
有一个文件夹中有好多文件:
9-13001-10.txt
9-13001-20.txt
9-13001-30.txt
5-13001-10.txt
5-13001-20.txt
5-13001-30.txt
11-13001-10.txt
11-13001-20.txt
11-13001-30.txt
...  ...
目的:把“文本名字中后8位数字完全一样的文本”中的内容读取后保存到以该8位数字命名的文本中,例如:把文本后8位数字全为“13001-10”的文本中的内容读取后保存到13001-10.txt中


[ 本帖最后由 菜鸟新上路 于 2010-5-21 09:47 编辑 ]
搜索更多相关主题的帖子: 批量 文件 
2010-05-21 09:43
jiashie
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:237
专家分:999
注 册:2009-4-30
收藏
得分:20 
中国的人口就是多,而且是低级重复地“多”。。。
就这么不舍得动脑子?这个问题又不涉及到多么高深的技术,纯粹就是个思路
程序代码:
'//! 引用Microsoft Scripting Runtime
Private Function foo(ByVal strPath As String) As Long
    Dim strFile  As String
    Dim strLast8 As String
    Dim dic      As Dictionary
    Dim fNo      As Integer
    Dim fNo2     As Integer
    Dim bytBuf() As Byte
    Dim arrList  As Variant
    Dim i        As Integer
    Dim j        As Integer

    Set dic = New Dictionary

    strFile = Dir$(strPath & "\*.txt")

    Do While strFile <> ""
        '获取文件名的最后8位
        strLast8 = Right$(Left$(strFile, InStrRev(strFile, ".") - 1), 8)
    
        On Error Resume Next

        dic.Add strLast8, strFile

        If Err Then
            dic(strLast8) = dic(strLast8) & "|" & strFile
        End If

        On Error GoTo 0
    
        strFile = Dir$()
    Loop

    For i = 0 To dic.Count - 1
        arrList = Split(dic.Items(i), "|")
    
        fNo = FreeFile()
        Open strPath & "\result\" & dic.Keys(i) & ".txt" For Binary As fNo

        For j = 0 To UBound(arrList)
            fNo2 = FreeFile()
            Open strPath & "\" & arrList(j) For Binary As fNo2
            ReDim bytBuf(LOF(fNo2)) As Byte
            
            Get fNo2, , bytBuf()
            Close fNo2
            Put fNo, , bytBuf()
        Next

        Close fNo
    Next

End Function



[ 本帖最后由 jiashie 于 2010-5-21 11:46 编辑 ]
2010-05-21 11:08
快速回复:如何批量读取文件夹中指定文件的内容??
数据加载中...
 
   



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

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