找回密码
 加入
搜索
查看: 3627|回复: 8

[AU3基础] 如何读取文件夹下的TXT文件并将文件内容逐行合并一个文件(结贴)

  [复制链接]
发表于 2011-3-8 01:49:31 | 显示全部楼层 |阅读模式
本帖最后由 夜猫猫 于 2011-3-11 03:47 编辑

比如1文件夹下有1.txt,1.txt.3.txt
1.txt内容为1111111111
2txt内容为2222222222
3.txt内容为3333333333
怎么读取他们,并将所有内容合并一起为4.txt
4.txt内容为其他三个txt的合并内容
即:4.txt
1111111111
2222222222
3333333333

下面是获取文件路径:
#include <File.au3>
#include <GUIConstantsEx.au3>

#Region ### START Koda GUI section ### Form=
Global $str, $file, $hFile, $FileList, $folder

$Form1 = GUICreate("", 473, 189, 192, 114)
$Input1 = GUICtrlCreateInput("", 48, 136, 225, 21)
$Button1 = GUICtrlCreateButton("读取", 220, 160, 57, 21)
$Button2 = GUICtrlCreateButton("打开", 300, 136, 57, 21)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 441, 113)
GUISetState(@SW_SHOW)

Func Ru()
$FileList=_FileListToArray($folder)
$file=FileOpen ("log.log",2)  
For $i = 1 To $FileList[0]
        FileWriteLine ($file, $folder&""&$FileList[$i])
Next    
FileClose($file)
EndFunc


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case  $Button1 
          Case  $Button2
                  $folder = FileSelectFolder("选择一个文件夹", "",1+4,"")
                  If Not @error Then
            Ru()
                  GUICtrlSetData($Edit1, "")
                  GUICtrlSetData($Edit1, FileRead(@ScriptDir&"\log.log"))              
                  EndIf
        EndSwitch
WEnd
发表于 2011-3-8 07:45:08 | 显示全部楼层
回复 1# 夜猫猫

$str1 = FileRead("F:\1.txt")
$str2 = FileRead("F:\2.txt")
$str3 = FileRead("F:\3.txt")
$str4 = $str1 & @CRLF & $str2 & @CRLF & $str3
FileWrite("F:\4.txt", $str4)
或者直接调用dos的copy命令吧
发表于 2011-3-8 07:48:41 | 显示全部楼层
你的“逐行”是啥意思,不会是如4.txt的前三行是分别是1.txt,2.txt,3.txt的第一行吧?
若是这样,你用FileReadLine()吧
发表于 2011-3-8 08:10:18 | 显示全部楼层
进来学习学习.
 楼主| 发表于 2011-3-9 06:26:46 | 显示全部楼层
逐行就是三楼说的。
郁闷!我用FileReadLine()写不进去,运行后4.TXT 是空白的。
发表于 2011-3-9 14:47:56 | 显示全部楼层
逐行就是三楼说的。
郁闷!我用FileReadLine()写不进去,运行后4.TXT 是空白的。
夜猫猫 发表于 2011-3-9 06:26

那个命令是读取的命令吧?
发表于 2011-3-9 18:20:01 | 显示全部楼层
filereadline
filewriteline
 楼主| 发表于 2011-3-11 03:45:44 | 显示全部楼层
FileWriteLine
发表于 2011-3-11 04:15:55 | 显示全部楼层
filewrite($file4, fileread($file1)&@crlf& fileread($file2)&@crlf&fileread($file3))
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-21 10:30 , Processed in 0.078003 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表