找回密码
 加入
搜索
查看: 1680|回复: 2

[AU3基础] 在拖放脚本中如何实现对文档的操作

[复制链接]
发表于 2010-4-8 14:55:02 | 显示全部楼层 |阅读模式
在拖放脚本中,我发现不能实现对文档的操作,脚本如下:
#include <File.au3>
#include<array.au3>

Global $x
If $cmdline[0] = 1 Then
   $x= $cmdline[1]
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)

请问问题是出在哪里呢?
发表于 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[0] = 1 Then
        $x = $cmdline[1]
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)
发表于 2010-4-9 07:47:55 | 显示全部楼层
本帖最后由 newuser 于 2010-4-9 07:58 编辑

回复 2# afan
怎么才能正常执行呢?
直接将test-zx.txt拖到AU3上执行,可直接将test-zx.txt拖到EXE上却不行啊!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-20 15:37 , Processed in 0.078485 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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