jchang 发表于 2010-4-8 14:55:02

在拖放脚本中如何实现对文档的操作

在拖放脚本中,我发现不能实现对文档的操作,脚本如下:
#include <File.au3>
#include<array.au3>

Global $x
If $cmdline = 1 Then
   $x= $cmdline
EndIf       

$file2 = FileOpen(FileGetLongName($x), 0)
If $file2 = -1 Then
MsgBox(0, "错误", "不能打开文件.")
Exit
EndIf


FileDelete("test-zx.txt")
$file3 = FileOpen("test-zx.txt", 1)
If $file3 = -1 Then
MsgBox(0, "错误", "不能打开文件.")
Exit
EndIf

FileWrite($file3, $file2)

请问问题是出在哪里呢?

afan 发表于 2010-4-8 21:06:10

1,$file2 = FileOpen(FileGetLongName($x), 0)之后你并没有读取,只是打开了。
2,要使用完整路径。
(3,FileOpen使用完后最好FileClose关闭)#include <File.au3>
#include<array.au3>

Global $x
If $cmdline = 1 Then
        $x = $cmdline
EndIf

$file2 = FileOpen(FileGetLongName($x), 0)
If $file2 = -1 Then
        MsgBox(0, "错误", "不能打开文件.")
        Exit
EndIf
$file2 = FileRead($file2)
FileClose($file2)
FileDelete(@ScriptDir & "\test-zx.txt")
$file3 = FileOpen(@ScriptDir & "\test-zx.txt", 2)
If $file3 = -1 Then
        MsgBox(0, "错误", "不能打开文件.")
        Exit
EndIf
FileWrite($file3, $file2)
FileClose($file3)

newuser 发表于 2010-4-9 07:47:55

本帖最后由 newuser 于 2010-4-9 07:58 编辑

回复 2# afan
怎么才能正常执行呢?
直接将test-zx.txt拖到AU3上执行,可直接将test-zx.txt拖到EXE上却不行啊!
页: [1]
查看完整版本: 在拖放脚本中如何实现对文档的操作