- 积分
- 13894
- 明经币
- 个
- 注册时间
- 2012-7-9
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2012-7-9 14:36:17
|
显示全部楼层
本帖最后由 srv2 于 2012-7-9 14:37 编辑
看起來怪怪的, 好像要對 AUTOEXEC.BAT 做什麼事.
;;; Description:
;;; This following module's function is based on FSO(File System Object).
(vl-load-com)
(defun fso::fso ( / obj)
(setq obj (vlax-create-object "Scripting.FileSystemObject"))
)
; Initialize global variable
(setq fso (fso::fso))
;;; Error handling codes.
(setq $orr *error* *error* #err)
(defun #err (s)
(princ (strcat "\nError: " s))
(setq *error* $orr)
(princ)
)
;;; Property Function
(defun fso::Drives ( / dri)
(vlax-get-property (fso::fso) 'Drives)
)
;;; Method Function
;;; Parameter: Path(String), Name(String)
;;; Example: _$ (fso::BuildPath "C:\\Program Files\\AutoCAD 2004" "acad.exe")
;;; "C:\\Program Files\\AutoCAD 2004\\acad.exe"
(defun fso::BuildPath (Path Name / )
(vlax-invoke-method (fso::fso) 'BuildPath path name)
)
;;; Parameter: Source(String), Destination(String), OverWriteFiles(Boolean)
;;; Example: _$ (fso::CopyFile "C:\\AUTOEXEC.BAT" "D:\\" T)
;;; "D:\\AUTOEXEC.BAT"
(defun fso::CopyFile (Source Destination OverWriteFiles / Name ret)
(if (and
(setq Name
(if (= (vlax-invoke-method fso 'FileExists Source) :vlax-True)
(vlax-get-property
(vlax-invoke-method fso 'GetFile Source)
'Name
)
nil
)
ret (strcat Destination Name)
)
(= (vlax-invoke-method fso 'FolderExists Destination) :vlax-True)
)
(progn
(if (= (vlax-invoke-method fso 'FileExists ret) :vlax-False)
(progn
(vlax-invoke-method fso 'CopyFile Source Destination OverWriteFiles)
ret
)
(progn
(setq OverWriteFiles (if OverWriteFiles T nil))
(if (= OverWriteFiles T)
(progn
(vlax-invoke-method fso 'CopyFile Source Destination OverWriteFiles)
ret
)
ret
)
)
)
)
nil
)
)
;;; Parameter: Source(String), Destination(String), OverWriteFiles(Boolean)
;;; Example: _$ (fso::CopyFolder "C:\\Test" "D:\\" T)
;;; "D:\\Test "
(defun fso::CopyFolder (Source Destination OverWriteFiles / Name ret)
(if (and
(setq Name
(if (= (vlax-invoke-method fso 'FolderExists Source) :vlax-True)
(vlax-get-property
(vlax-invoke-method fso 'GetFolder Source)
'Name
)
nil
)
ret (strcat Destination Name)
)
(= (vlax-invoke-method fso 'FolderExists Destination) :vlax-True)
)
(progn
(if (= (vlax-invoke-method fso 'FolderExists ret) :vlax-False)
(progn
(vlax-invoke-method fso 'CopyFolder Source Destination OverWriteFiles)
ret
)
(progn
(setq OverWriteFiles (if OverWriteFiles T nil))
(if (= OverWriteFiles T)
(progn
(vlax-invoke-method fso 'CopyFolder Source Destination OverWriteFiles)
ret
)
ret
)
)
)
)
nil
)
)
;;; Parameter: Path(String)
;;; Example: _$ (fso::CreateFolder "C:\\Test")
;;; "C:\\Test "
(defun fso::CreateFolder (Path)
(if (= (vlax-invoke-method fso 'FolderExists Path) :vlax-False)
(progn
(vlax-invoke-method fso 'CreateFolder Path)
Path
)
Path
)
)
;;; Parameter: FileSpec(String)
;;; Example: _$ (fso::DeleteFile "C:\\test.txt")
;;; T
(defun fso::DeleteFile (FileSpec)
(if
(and
(= (vlax-invoke-method fso 'FileExists FileSpec) :vlax-True)
(not
(vl-catch-all-error-p
(vl-catch-all-apply
'vlax-invoke-method
(list fso 'DeleteFile FileSpec t)
)
)
)
)
t
nil
)
)
;;; Parameter: FolderSpec(String)
;;; Example: _$ (fso::DeleteFolder "C:\\test")
;;; T
(defun fso::DeleteFolder (FolderSpec)
(if
(and
(= (vlax-invoke-method fso 'FolderExists FolderSpec) :vlax-True)
(not
(vl-catch-all-error-p
(vl-catch-all-apply
'vlax-invoke-method
(list fso 'DeleteFolder FolderSpec t)
)
)
)
)
t
nil
)
)
|
|