初级视频编辑室|草蜢非编论坛|初级视编室|草蜢视频编辑|会声会影|威力导演|电子相册

 找回密码
 加入初编室
搜索
查看: 803|回复: 2
打印 上一主题 下一主题

[Director 多媒体爱好者] FileIO Xtra应用实例

[复制链接]

296

主题

1132

帖子

2万

积分

超级版主

Rank: 8Rank: 8

论坛版主精华帖勋章

跳转到指定楼层
楼主
发表于 2014-11-24 21:34:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
onekey onekey
1. 用“Open”对话框将文本文件读取到域里

  以下处理程序将一文本件文读取到一域文本演员中(演员名称为“myfield”)。这种方法允许你从标准的Macintosh或Windows系统的“Open”对话框选择文件。

on readFromFile
  global myFile
  if objectp(myFile) then set myFile = 0--替换当前“myfile‘‘中的文本
  set myFile = new(xtra "fileio")--建立一个FileIO的事例
  if the machinetype = 256 then
    setfiltermask(myfile,"All files,*.*,Text files,*.txt")--指定文件类型(win)
  else
    setfiltermask(myfile,"Text")--指定文件类型(mac)
  end if
  set filename = displayOpen(myFile)--显示“Open”对话框
  if not voidp(filename) and not(filename = EMPTY) then
    openFile(myFile,filename,1)--打开用户选择的文件
    if status(myFile) = 0 then
      set thefile = readFile(myFile)--读取文件到一个lingo变量中
      put thefile into field"myField"--在域中显示文本
    else
      alert error(myfile,status(myfile))--显示报错
    end if
  end if
  closeFile(myFile)--关闭文件
  set myFile = 0
end

  2. 向文本域中写入数据

  以下程序可以建立并写入文本文件。movie里包含了一域演员“myfield”,与程序在同一文件夹包含一文本文件“textfile.txt”。程序里用到的“setFinderInfo”在Macintosh系统上可以通过SimpleText识别文本文件,在Windows系统上“setFinderInfo”在编译时被忽略,因此对于不同的机器,注意Lingo的细节问题是有必要的。

on writeToFile
  global myfile
  if objectp(myfile) then set myfile = 0--替换当前“myfile‘‘中的文本
  set theFile = the text of field "myfield"--将‘‘myfield‘‘中的文本置给变量
  set myFile = new(xtra "fileio")--建立一个FileIO的事例
  if the moviepath = "" then
    alert "no moviepath! save your movie and try again."--确保路径不为空
  else
    createFile (myfile, the moviepath&"textfile.txt")--建立文本文件
    openFile (myfile, the moviepath&"textfile.txt",0)--只读方式打开文件
    setfinderinfo (myfile, "TEXT ttxt")--建立文件(mac)
    writeString(myfile, theFile)--向文件中写入字符
    alert "status:"&error(myFile,status(myFile))--显示报错
  end if
  closeFile (myfile)--关闭文件
  set myFile = 0
end

  3. 给文本添加数据

  以下程序为文本添加数据。movie中包含了一域文本演员“myfield”。与程序在同一文件夹包含一文本文件“textfile.txt”。

on appendtofile
  global myFile
  if objectp(myFile) then set myFile = 0--替换当前“myfile”中的文本
  set theFile = the text of field "myfield"--将“myfield”中的文本置给变量
  set myFile = new(xtra "fileio")--建立一个FileIO的事例
  if the moviepath = "" then
    alert "no moviepath! please save your movie and try again."
  else
    openFile(myfile, the moviepath&"textfile.txt",0)--只读方式打开文件
    setposition(myfile,getlength(myfile))
    writestring(myfile,thefile)--添加文本
    alert "status:"&error(myfile,status(myfile))--显示报错
  end if
  closefile (myfile)--关闭文件
  set myfile=0--dispose of the instance
end

  4. 以下程序删除文本文件“textfile.txt”

on deletefile
  global myfile
  if objectp(myfile) then set myfile = 0--替换当前“myfile”中的文本
  set myfile=new(xtra "fileio")--建立一个FileIO的事例
  if the moviepath="" then
    alert "no moviepath,please save your movie and try again."
  else
    openfile (myfile, the moviepath&"textfile.txt",0)--打开文件
    delete(myfile)--删除当前文件
    alert "status:"& error(myfile,status(myfile))--显示报错
  end if
  closefile (myfile)--关闭文件
  set myfile = 0
end

  5. 返回Windows or Macintosh的系统文件夹的路径

  Getosdirectory()函数返回Windows or Macintosh的系统文件夹的绝对路径。使用它不需要引用任何变量,而只需要在Message窗口写入下列语句:

  put getosdirectory()

  回车后显示:
  --"c:MyWin95" --Windows
  --"My HardDirve:System Folder" --Macintosh
楼主热帖
河边已是一首歌
回复

使用道具 举报

206

主题

4449

帖子

7万

积分

初编室元帅

Rank: 14Rank: 14Rank: 14Rank: 14

活跃会员帅哥会员百帖纪念荣誉勋章论坛万元户

沙发
发表于 2014-11-24 21:58:27 | 只看该作者
谢谢楼主提供分享!!

131

主题

5672

帖子

11万

积分

初编室元帅

Rank: 14Rank: 14Rank: 14Rank: 14

帅哥会员活跃会员论坛万元户百帖纪念荣誉勋章

板凳
发表于 2015-1-21 11:48:26 | 只看该作者
阳春白雪,逛一逛,看一看,顶一顶。
您需要登录后才可以回帖 登录 | 加入初编室

本版积分规则

手机版|小黑屋|初级视频编辑室

GMT+8, 2024-6-2 02:54 , Processed in 0.069066 second(s), 30 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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