wsycharles0o 发表于 2010-8-27 13:17:55

FILE函数相关问题...@Error没变,于是不断复写...

好吧....
谁解释一下,这个程序传完文件没有像帮助文件里写的那样SET @Error=1,于是它就在那里不断复写....HotKeySet("{F8}","QUIT")

Func QUIT()
        Exit
EndFunc

Global $READPATH,$WRITEPATH,$READ,$WRITE,$DATA,$KB=0

$READPATH=InputBox("FILE","Target:")
$WRITEPATH=InputBox("FILE","To:")
$NAME=InputBox("FILE","Name:")

$READ=FileOpen($READPATH,16)
$WRITE=FileOpen($WRITEPATH&$NAME,16+2)

While (@error = 0)
$DATA=FileRead($READ,1024)
FileWrite($WRITE,$DATA)
$KB=$KB+1
ToolTip("KB:"&$KB,0,0)
WEnd

MsgBox(0,"FILE","DONE!")

FileClose($READ)
FileClose($WRITE)

afan 发表于 2010-8-27 13:20:28

While (@error = 0) 这个@Error 是哪个的@error ..

wsycharles0o 发表于 2010-8-27 13:23:02

回复 2# afan
额?
FileRead的...
貌似帮助文件里说FileRead完就会把@Error设为-1

Ziya 发表于 2010-8-27 13:25:46

但是你没有告诉程序,让它去读FileRead的@Error

Ziya 发表于 2010-8-27 13:27:26

$file = FileOpen("test.txt", 0)

; 检查打开的文件是否可为读
If $file = -1 Then
    MsgBox(0, "错误", "不能打开文件.")
    Exit
EndIf

; 每次读取一个字符,直到文件结束(译注:读中文必须设置为远大于1的值!)(译注的译注(thesnow):ANSI编码中,一个中文为两个字符/字节)
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    MsgBox(0, "读取的字符:", $chars)
Wend

FileClose($file)看下帮助里给的例子

wsycharles0o 发表于 2010-8-27 13:28:18

回复 4# Ziya


huh?
While(@error=0)不就是这个目的么?

wsycharles0o 发表于 2010-8-27 13:33:38

回复 5# Ziya


程序做如下修改,问题依然存在...
while 部分改为:While 1
        If @error = -1 Then ExitLoop
        $DATA=FileRead($READ,1024)
        FileWrite($WRITE,$DATA)
        $KB=$KB+1
        ToolTip("KB:"&$KB,0,0)
WEnd其它没变...

afan 发表于 2010-8-27 13:35:47

本帖最后由 afan 于 2010-8-27 13:40 编辑

2、3行调个个

wsycharles0o 发表于 2010-8-27 13:37:03

回复 8# afan


斑竹明示...

afan 发表于 2010-8-27 13:39:40

Local $_DATA
While 1
      $DATA=FileRead($READ,1024)
      If @error = -1 Then ExitLoop
      $_DATA &= $DATA
      $KB += 1
      ToolTip("KB:"&$KB,0,0)
WEnd
FileWrite($WRITE,$_DATA) ;只写入一次即可

wsycharles0o 发表于 2010-8-27 13:45:07

回复 10# afan


额...
问题依旧...
不过不写了...开始无限读了...

wsycharles0o 发表于 2010-8-27 13:47:12

回复 10# afan


莫非是版本问题?
WINDOWS XP PROFESSIONAL SP3 2002
AUTOIT v3.3.6.1

不然就是人品问题...

afan 发表于 2010-8-27 13:51:05

回复 12# wsycharles0o


    莫非 @Error = 1?

wsycharles0o 发表于 2010-8-27 13:53:51

回复 13# afan


我的最初程序是while (@error=0)
所以@error是任何其它都会结束......
迫不得已,初步用FILEGETSIZE解决问题...但是依然不知为何@error不变...

afan 发表于 2010-8-27 13:55:52

While 1
      $DATA=FileRead($READ,1024)
      If @error = -1 Then ExitLoop
      ToolTip(@error & "KB:"&$KB,0,0)
      $KB += 1
WEnd看看@Error是1还是-1
页: [1] 2
查看完整版本: FILE函数相关问题...@Error没变,于是不断复写...