peraperson 发表于 2016-3-9 16:34:34

请问如何对一个文件夹下的所有txt文本进行批量操作

本帖最后由 peraperson 于 2016-3-9 16:35 编辑

比如将该文件夹下所有的txt文本的第一行删除之类的
麻烦大神们提供下大概的框架 谢谢

gaoheli_2008 发表于 2018-10-10 10:40:54

有没有

alin 发表于 2018-10-10 14:43:44

用lisp里Open, read, write-line, close几个命令

lisperado 发表于 2018-10-10 17:04:28

本帖最后由 lisperado 于 2018-10-10 17:07 编辑

请先备份! 原始文件将被覆盖!


(defun c:tt (/ *error* f fd fl fn l out str tmp)
(defun *error* (msg) (if f (close f)) )
(alert "\n文本的第一行删除!后果自负!")
(prompt "\n请选择文件夹 \n")
(if
    (and (princ (setq fd (acet-ui-pickdir)))
       (setq fl (vl-directory-files fd "*.txt"))
       (foreach x fl
         (and
                (setq l nil fn (strcat fd "\\" x)
                      f(open fn "r")
                      )
                (while (setq str (read-line f)) (setq l (cons str l)))
                (progn (if f (close f))
       (setq tmp (vl-filename-mktemp))
       (setq out (open tmp "w"))
       (foreach x (cdr (reverse l)) (write-line x out))
            (if out
                (close out)
                )
            (vl-file-delete fn)
            (vl-file-rename tmp fn)
            (terpri)
            (princ x)
            ) ;progn
       ); and
       ); foreach
       ); and
    (princ "\n执行完毕!")
    (princ "\n无文件?")
    )
   (textscr)
(princ)
)

xink 发表于 2018-10-15 20:34:58

小生有礼了,前来学习下

yoyoho 发表于 2019-3-29 08:04:03

谢谢! lisperado 分享学习!!!!!!
页: [1]
查看完整版本: 请问如何对一个文件夹下的所有txt文本进行批量操作