明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1387|回复: 3

文件操作

[复制链接]
发表于 2006-12-25 10:32:00 | 显示全部楼层 |阅读模式
请问一下:如何对文件进行写操作。(要求:打开一个文件,删除原文件中的内容,再写入新内容到文件中去)
发表于 2006-12-25 11:46:00 | 显示全部楼层

(open fn "w")就行。

 楼主| 发表于 2006-12-27 20:13:00 | 显示全部楼层

能给一段源代码吗?

发表于 2006-12-27 22:19:00 | 显示全部楼层

;;;==================
;;;= 读取文件到表中 =
;;;==================
(defun fcp::readfile (filename / fileobj str outlist)
  (setq outlist nil)
  (if
    (findfile filename)
     (progn
       (setq fileobj (open filename "r")
      str     (read-line fileobj)
       )
       (while (/= str nil)
  (setq outlist (append outlist (list str))
        str     (read-line fileobj)
  )
       )
       (close fileobj)
     )
     (alert (strcat "文件不能打开!请查询\n"
      filename
      "这个文件是否存在?"
     )
     )
  )
  outlist
)

;;;========================
;;;= 将表中的内容写入文件 =
;;;========================
(defun fcp::writefile (filename inlist intype / fileobj outlist)
  (setq outlist nil
 fileobj (open filename intype)
  )
  (if fileobj
    (progn
      (mapcar '(lambda (x) (write-line x fileobj)) inlist)
      (close fileobj)
      (setq outlist t)
    )
    (alert (strcat "文件不能打开!请查询\n"
     filename
     "文件名是否正确?"
    )
    )
  )
  outlist
)
;;;============
;;;= 重写文件 =
;;;============
(defun fcp::writefilew (filename inlist)
  (fcp::writefile filename inlist "w")
)
;;;============
;;;= 改写文件 =
;;;============
(defun fcp::writefilea (filename inlist)
  (fcp::writefile filename inlist "a")
)

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-11-23 11:35 , Processed in 0.182454 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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