本帖最后由 dunphy 于 2014-11-8 20:49 编辑
打个比方你要找的错误字符为@,(如果是更复杂的需要正则), 将四个文本放到D盘1234文件夹下
1.txtsdfasdfsadfasdadfasdfasdfasdfs!ER#$@sdfasdfsadfasdadfasdfasdfas
2.txtsdfasdfsad@fasdadfasdfasdfasdfs!ER#$@sdfasdfsadfasdadfasdfasdfas
sdfasdfsadfasdadfasdfasdfasdfs!ER#$@sdfasdfsadfasdadfasdfasdfas
3.txtsdfsdfsf@w32
dsfgsg@dvsfgds
advsfgfhnjt5
Sdsdfgdgdgh
dsfw43@wrgt35y45@jmryjr
4.txtadvfssfdfbg5324353@wr535t3y
ergergy43@243453
@Vadgwrgwg
VDsaf@gryjhr
代码如下:
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
Local $path = "d:\1234"
Local $aFileList = _FileListToArray($path, "*.txt")
If @error = 1 Then
MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
Exit
EndIf
If @error = 4 Then
MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
Exit
EndIf
; Display the results returned by _FileListToArray.
_ArrayDisplay($aFileList, "$aFileList")
Local $i, $aRetArray
For $i = 1 To UBound($aFileList) - 1 Step 1
_FileReadToArray($aFileList[$i], $aRetArray, 1)
_ArrayDisplay($aRetArray, "$aRetArray")
Local $j
For $j = 1 To UBound($aRetArray) - 1
Local $start = StringInStr($aRetArray[$j], "@") ;这里是你需要查找的错误字符
If $start <> "" Then
MsgBox(0, "提示", "在文件" & $aFileList[$i] & "中,第" & $j & "行,第" & $start & "个字符" & @CRLF & "有错误的字符@")
EndIf
Next
Next
|