将一文本复制到另以文本,不能重复
本帖最后由 xlcwxl 于 2010-1-15 18:56 编辑怎样将1.txt中的内容复制到2.txt中,不能重复。
1.txt内容:
1111111
aaaaaaa
2222222
bbbbbbb
2.txt内容:
ddddddd
点击复制后2.txt内容是:
ddddddd
1111111
aaaaaaa
2222222
bbbbbbb
不能重复,也不能删除之前的内容,能做到吗?
以下能写入,但是每写一次就重复一次$var = IniReadSection("config.txt", "list")
If @error Then
MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
For $i = 1 To $var
FileWrite('new.txt', @CRLF&$var[$i])
Next
EndIf IF Iniread ("","","") <> $var[$i] Then FileWrite('new.txt', @CRLF&$var[$i])
这样行不? 本帖最后由 C.L 于 2010-1-15 23:46 编辑
我的笨办法:
Dim $afile1, $afile2
WriteFile("1.txt", "2.txt")
Func ReadFile1ToArray($file)
$file1 = FileOpen($file, 0)
$i = 0
While 1
$line = FileReadLine($file1)
If @error Then
FileClose($file1)
ExitLoop
EndIf
If $line Then
$afile1[$i] = $line
$i += 1
ReDim $afile1
EndIf
WEnd
ReDim $afile1
EndFunc ;==>ReadFile1ToArray
Func ReadFile2ToArray($file)
$file2 = FileOpen($file, 0)
$i = 0
While 1
$line = FileReadLine($file2)
If @error Then
FileClose($file2)
ExitLoop
EndIf
If $line Then
$afile2[$i] = $line
$i += 1
ReDim $afile2
EndIf
WEnd
ReDim $afile2
EndFunc ;==>ReadFile2ToArray
Func WriteFile($read, $write)
ReadFile1ToArray($read)
ReadFile2ToArray($write)
$file3 = FileOpen($write, 1)
For $i = 0 To UBound($afile1) - 1
$flag = 1
For $j = 0 To UBound($afile2) - 1
If $afile1[$i] == $afile2[$j] Then
$flag = 0
ExitLoop
EndIf
Next
If $flag Then FileWriteLine($file3, $afile1[$i])
Next
FileClose($file3)
ShellExecute($write)
EndFunc ;==>WriteFile
记得这种问题,afan回答n遍了,麻烦楼主学会搜索
页:
[1]