找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 871|回复: 3

[密技]:VLISP中使用 WSH操控文件和文件夹

[复制链接]
发表于 2004-1-9 13:06:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

  1. ;|  Intellegent TypeLib loader
  2. Syntax: (vlax-load-type-libeary ProgID[STRING] UniquePrefix[STR])
  3.         (vlax-load-type-libeary ProgID[STRING] PrefixList[STR])
  4.   ARG1: ProgID string same used in vlax-get-create-object function
  5.   ARG2: Can be string or a list.
  6.         List order is (:methods-prefix :properties-prefix :constants-prefix)
  7. Description:
  8.     This function read Windows REGISTRY and try to detect the proper DLL/OCX/EXE type library
  9. file and load the type library automatically.
  10. Return Value:
  11. [Success]: T
  12. [F a i l]: NIL
  13. |;
  14. (Defun vlax-load-type-library
  15.        (File Prefix / FileX Host N KeyX Val OSVar rtn)
  16.   (setq        Host "HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\CLSID"
  17.         N    -1
  18.         KeyX (vl-registry-descendents Host)
  19.   )
  20.   (while (< (setq N (1+ N))
  21.             (length KeyX)
  22.          )
  23.     (if        (and (setq Val (vl-registry-read
  24.                          (strcat Host "\" (nth N KeyX) "\\ProgID")
  25.                        )
  26.              )
  27.              (vl-string-search (strcase File) (strcase Val))
  28.         )
  29.       (setq FileX (vl-registry-read
  30.                     (strcat Host "\" (nth N KeyX) "\\InProcServer32")
  31.                   )
  32.             N          (length KeyX)
  33.       )
  34.     )
  35.   )
  36.   (if (= (type Prefix) 'STR)
  37.     (setq Prefix (list Prefix Prefix (strcat ":" Prefix)))
  38.   )
  39.   (if (= (type FileX) 'LIST)
  40.     (setq FileX (cdr FileX))
  41.   )
  42.   (if (= (type FileX) 'STR)
  43.     (progn
  44.       (setq FileX (strcase FileX))
  45.       (foreach OSVar (list "SYSTEMROOT"             "WINDIR"
  46.                            "WINBOOTDIR"             "SYSTEMDRIVE"
  47.                            "USERNAME"             "COMPUTERNAME"
  48.                            "HOMEDRIVE"             "HOMEPATH"
  49.                            "PROGRAMFILES"
  50.                           )
  51.         (if (vl-string-search (strcat "%" OSVar "%") FileX)
  52.           (setq        FileX (vl-string-subst
  53.                         (strcase (getenv OSVar))
  54.                         (strcat "%" OSVar "%")
  55.                         FileX
  56.                       )
  57.           )
  58.         )
  59.       )
  60.       (if (setq rtn (findfile FileX))
  61.         (setq rtn
  62.                (vlax-import-type-library
  63.                  :tlb-filename
  64.                  FileX
  65.                  :methods-prefix
  66.                  (nth 0 Prefix)
  67.                  :properties-prefix
  68.                  (nth 1 Prefix)
  69.                  :constants-prefix
  70.                  (nth 2 Prefix)
  71.                )
  72.         )
  73.       )
  74.     )
  75.   )
  76.   rtn
  77. )
  78. ;|  convert all "/" in path into "\" and return all upper letters
  79. Syntax: (vldos-formatpath PathStringToFormat[STRING])
  80.   ARG1: The path string
  81. Description:
  82.     This function will convert all "/" in path into DOS "\".
  83. Return Value:
  84. [Success]: New label string
  85. [F a i l]: None
  86. |;
  87. (Defun vldos-formatpath        (string)
  88.   (while (vl-string-search "/" string)
  89.     (setq string (vl-string-subst "\" "/" string))
  90.   )
  91.   (while (vl-string-search "\\\" string)
  92.     (setq string (vl-string-subst "\" "\\\" string))
  93.   )
  94.   (setq string (strcase string))
  95.   string
  96. )
  97. ;|  Label the volume name of local drive
  98. Syntax: (vldos-label DriveLetter[STRING] NewVolumnName[STRING])
  99.   ARG1: The drive letter such as "C" or "C:"
  100.   ARG2: New volumn name string, if the length of given string is bigger than 11, automatically cut
  101.         <<< Function will not check if the string is valid for a drive volume name >>>
  102. Description:
  103.     Re-label the volume name of a certain local drive. If you are in intranet, be sure that you have enough
  104. rights to do this via MS-DOS mode.
  105. Return Value:
  106. [Success]: New label string
  107. [F a i l]: NIL
  108. |;
  109. (Defun vldos-Label (DRV NEW / Fil DDD ERR)
  110.   (if (> (strlen NEW) 11)
  111.     (setq NEW (substr New 1 11))
  112.   )
  113.   (if (null
  114.         (setq
  115.           Fil (vlax-get-or-create-object "Scripting.FileSystemObject")
  116.         )
  117.       )
  118.     (setq New nil)
  119.     (progn
  120.       (setq DDD (vlax-invoke-method Fil 'GetDrive DRV))
  121.       (vlax-put-property DDD "VolumeName" NEW)
  122.       (if (not (eq (setq NEW (strcase NEW))
  123.                    (strcase (vlax-get-property DDD "VolumeName"))
  124.                )
  125.           )
  126.         (setq NEW nil)
  127.       )
  128.       (vlax-release-object DDD)
  129.       (vlax-release-object FIL)
  130.     )
  131.   )
  132.   NEW
  133. )
  134. ;|  Perform DOS DELTREE operation
  135. Syntax: (vldos-deltree DirectoryToDelete[STRING])
  136.   ARG1: The directory name that to be deleted. This function will not perform an confirm interface and will
  137.         delete the folder and all the sub-folders quietly.
  138.         If the root folder is indicated, this function will automatically deltree all sub-folders in root.
  139. Description:
  140.     Run DOS DELTREE/Y command via ActiveX. No confirm, no backup.
  141.     Return Value:
  142. [Success]: T
  143. [F a i l]: NIL
  144. |;
  145. (Defun vldos-Deltree (Folder / sf subf FIL Rtn)
  146.   (cond        ((vl-file-directory-p Folder)
  147.          (if (null (setq Fil
  148.                           (vlax-get-or-create-object "Scripting.FileSystemObject")
  149.                    )
  150.              )
  151.            (setq Rtn nil)
  152.            (progn
  153.              (cond
  154.                ((<= (strlen Folder) 3)
  155.                 (if (= (strlen folder) 2)
  156.                   (setq folder (strcat folder "\"))
  157.                 )
  158.                 (setq subf (vl-directory-files Folder nil -1)
  159.                       subf (vl-remove "." subf)
  160.                       subf (vl-remove ".." subf)
  161.                       subf (vl-remove "Recycled" subf)
  162.                 )
  163.                 (foreach sf subf
  164.                   (vlax-invoke-method
  165.                     Fil
  166.                     'DeleteFolder
  167.                     (strcat folder sf)
  168.                     T
  169.                   )
  170.                 )
  171.                )
  172.                (t (vlax-invoke-method Fil 'DeleteFolder Folder T))
  173.              )
  174.              (vlax-release-object FIL)
  175.              (setq Rtn (not (vl-file-directory-p Folder)))
  176.            )
  177.          )
  178.         )
  179.         ((findfile Folder)
  180.          (vl-file-delete folder)
  181.          (setq Rtn (not (findfile Folder)))
  182.         )
  183.   )
  184.   Rtn
  185. )
  186. ;|  Create folder
  187. Syntax: (vldos-mkdir DirectoryToCreate[STRING])
  188.   ARG1: The full path name of directory to be created. This function will automatically create all non-existing
  189.         directories in this argument.
  190. Description:
  191.     Super tools to create nest-folders, more convinient that do in MS-DOS.
  192. Return Value:
  193. [Success]: Full path name string of folder created
  194. [F a i l]: NIL
  195. |;
  196. (Defun vldos-MkDir (Folder / FolderX Fil FFF Pos DIR DRV)
  197.   (if (null
  198.         (setq
  199.           Fil (vlax-get-or-create-object "Scripting.FileSystemObject")
  200.         )
  201.       )
  202.     (setq Folder nil)
  203.     (progn
  204.       (while (vl-string-search "/" Folder)
  205.         (setq Folder (vl-string-subst "\" "/" Folder))
  206.       )
  207.       (if (wcmatch Folder "*\")
  208.         (setq Folder (substr Folder 1 (1- (strlen Folder))))
  209.       )
  210.       (setq FolderX Folder)
  211.       (while (setq Pos (vl-string-search "\" Folder))
  212.         (setq FFF    (cons (substr Folder 1 Pos) FFF)
  213.               Folder (substr Folder (+ Pos 2))
  214.         )
  215.       )
  216.       (setq FFF        (reverse (cons Folder FFF))
  217.             DRV        (car FFF)
  218.             FFF        (cdr FFF)
  219.       )
  220.       (foreach DIR FFF
  221.         (if
  222.           (null        (vl-file-directory-p (setq DRV (strcat DRV "\" DIR)))
  223.           )
  224.            (vlax-invoke-method
  225.              Fil
  226.              'createfolder
  227.              DRV
  228.            )
  229.         )
  230.       )
  231.       (vlax-release-object Fil)
  232.       (if (setq Folder (vl-file-directory-p FolderX))
  233.         (setq Folder (vldos-formatpath FolderX))
  234.       )
  235.     )
  236.   )
  237.   Folder
  238. )
  239. ;|  Copy file or folders
  240. Syntax: (vldos-copy SourceFile/Directory[STRING] TargetFile/Directory[STRING])
  241.   ARG1: The source file or directory to be copied.
  242.   ARG2: The destination location. If contain "*\" or "*/", this function will create a same nest-folder
  243.         name under this path while performing copy folder operation.
  244. Description:
  245.     Copy a file or a folder.
  246. Return Value:
  247. [Success]: New created file or folder name string.
  248. [F a i l]: NIL
  249. |;
  250. (Defun vldos-copy (from to / sys folder)
  251.   (setq        from (vldos-formatpath from)
  252.         to   (vldos-formatpath to)
  253.   )
  254.   (if (null (vl-file-directory-p to))
  255.     (setq to (vldos-mkdir to))
  256.   )
  257.   (if (setq sys (vlax-get-or-create-object "Shell.Application"))
  258.     (progn
  259.       (if (setq folder (vlax-invoke-method sys 'namespace to))
  260.         (progn
  261.           (princ
  262.             (strcat "\n Copying file(s) from \042"
  263.                     FROM                   "\042 to \042"
  264.                     to                           "\042..."
  265.                    )
  266.           )
  267.           (vlax-invoke-method folder 'copyhere from (+ 4 16))
  268.           (vlax-release-object folder)
  269.           (princ "...Done!")
  270.         )
  271.       )
  272.       (vlax-release-object sys)
  273.     )
  274.   )
  275.   (princ)
  276. )
  277. ;|(Defun vldos-copy2 (From to / rtn)
  278.   (cond
  279.     ((vl-file-directory-p From)
  280.      (if (< (strlen to) 3)
  281.        (setq to (strcat to "\"))
  282.        (if (not (vl-file-directory-p to))
  283.          (vldos-mkdir to)
  284.        )
  285.      )
  286.      (if (setq
  287.            Rtn (vlax-get-or-create-object "Scripting.FileSystemObject")
  288.          )
  289.        (progn
  290.          (vlax-invoke-method Rtn 'CopyFolder From to T)
  291.          (vlax-release-object Rtn)
  292.          (if (vl-file-directory-p to)
  293.            (setq Rtn (vldos-formatpath to))
  294.          )
  295.        )
  296.      )
  297.     )
  298.     ((findfile From)
  299.      (vl-file-copy From to)
  300.      (if (setq rtn (findfile to))
  301.        (setq rtn (vldos-formatpath rtn))
  302.      )
  303.     )
  304.   )
  305.   rtn
  306. )
  307. |;
  308. ;|  Move file or folders
  309. Syntax: (vldos-move SourceFile/Directory[STRING] TargetFile/Directory[STRING])
  310.   ARG1: The source file or directory to be moved.
  311.   ARG2: The destination location. If contain "*\" or "*/", this function will create a same nest-folder
  312.         name under this path while performing copy folder operation.
  313. Description:
  314.     Move a file or a folder.
  315. Return Value:
  316. [Success]: New file or folder name path string.
  317. [F a i l]: NIL
  318. |;
  319. (Defun vldos-move (from to / sys folder)
  320.   (if (setq sys (vlax-get-or-create-object "Shell.Application"))
  321.     (progn
  322.       (setq from   (vldos-formatpath from)
  323.             to           (vldos-formatpath to)
  324.             folder (vlax-invoke-method sys 'namespace to)
  325.       )
  326.       (if folder
  327.         (progn
  328.           (princ
  329.             (strcat "\n Moving file(s) from \042"
  330.                     FROM                   "\042 to \042"
  331.                     to                           "\042..."
  332.                    )
  333.           )
  334.           (vlax-invoke-method folder 'movehere from (+ 4 16))
  335.           (vlax-release-object folder)
  336.           (princ "...Done!")
  337.         )
  338.       )
  339.       (vlax-release-object sys)
  340.     )
  341.   )
  342.   (princ)
  343. )
  344. ;|  Move file or folders
  345. Syntax: (vldos-rename SourceFile/Directory[STRING] NewName[STRING])
  346.   ARG1: The source file or directory to be moved.
  347.   ARG2: The destination location. If contain "*\" or "*/", this function will create a same nest-folder
  348.         name under this path while performing copy folder operation.
  349. Description:
  350.     Move a file or a folder.
  351. Return Value:
  352. [Success]: New file or folder name path string.
  353. [F a i l]: NIL
  354. |;
  355. (Defun vldos-rename (From to / Fil folder new parent rtn)
  356.   (cond
  357.     ((vl-file-directory-p From)
  358.      (setq parent (vl-filename-directory From)
  359.            new          (strcat parent to)
  360.      )
  361.      (if (and (setq
  362.                 Fil
  363.                  (vlax-get-or-create-object "Scripting.FileSystemObject")
  364.               )
  365.               (> (strlen From) 3)
  366. ;;; Can not rename root folder
  367.               (null (vl-file-directory-p new))
  368. ;;; not an existing folder name
  369.          )
  370.        (progn
  371.          (setq folder (vlax-invoke-method Fil 'GetFolder From))
  372.          (vlax-put-property folder "Name" To)
  373.          (vlax-release-object folder)
  374.          (vlax-release-object Fil)
  375.        )
  376.        (setq parent nil)
  377.      )
  378.     )
  379.     ((findfile From)
  380.      (setq parent (vl-filename-directory from))
  381.      (vl-file-rename From to)
  382.     )
  383.   )
  384.   (if (and parent
  385.            (vl-file-directory-p
  386.              (setq to (strcat parent to))
  387.            )
  388.       )
  389.     (setq rtn (vldos-formatpath to))
  390.   )
  391.   rtn
  392. )
  393. (Defun vldos-drivetype (drv / Fil drives drive typ rtn)
  394.   (setq rtn "INVALID")
  395.   (if
  396.     (and (setq
  397.            Fil (vlax-get-or-create-object "Scripting.FileSystemObject")
  398.          )
  399.          (equal :vlax-true (vlax-invoke-method Fil 'DriveExists drv))
  400.     )
  401.      (progn
  402.        (setq drives (vlax-get-property Fil 'Drives)
  403.              drive  (vlax-get-property drives 'Item drv)
  404.              typ    (vlax-get-property drive 'DriveType)
  405.              rtn    (nth typ
  406.                          (list "UNKNOWN"     "REMOVABLE"
  407.                                "FIXED"             "REMOTE"
  408.                                "CDROM"             "RAMDISK"
  409.                               )
  410.                     )
  411.        )
  412.        (vlax-release-object drive)
  413.        (vlax-release-object drives)
  414.        (vlax-release-object Fil)
  415.      )
  416.   )
  417.   rtn
  418. )
  419. (Defun vldos-alldrive (/ fil drive drives lst)
  420.   (if (setq Fil (vlax-get-or-create-object "Scripting.FileSystemObject"))
  421.     (progn
  422.       (vlax-for        drive (setq drives (vlax-get-property Fil 'Drives))
  423.         (setq lst (cons (vlax-get-property drive 'DriveLetter) lst))
  424.       )
  425.       (vlax-release-object drives)
  426.       (vlax-release-object Fil)
  427.       (setq lst (reverse lst))
  428.     )
  429.   )
  430.   lst
  431. )
  432. (Defun vldos-driveinfo (Drv Key / pos rtn)
  433.   (if (/= (type key) 'STR)
  434.     (setq rtn (vldos-alldriveinfo drv))
  435.     (if        (setq pos (vl-position
  436.                     (setq key (strcase key))
  437.                     (list "TOTALSIZE"            "FREESPACE"
  438.                           "DRIVETYPE"            "FILESYSTEM"
  439.                           "SERIALNUMBER"    "SHARENAME"
  440.                           "VOLUMENAME"
  441.                          )
  442.                   )
  443.         )
  444.       (setq rtn (nth pos (vldos-alldriveinfo drv)))
  445.     )
  446.   )
  447.   rtn
  448. )
  449. (Defun vldos-alldriveinfo (Drv / DrvObj FilSys RetVal)
  450.   (if (setq
  451.         FilSys (vlax-get-or-create-object "Scripting.FileSystemObject")
  452.       )
  453.     (progn
  454.       (setq RetVal
  455.              (cond
  456.                ((= (vlax-invoke FilSys "DriveExists" Drv) 0) 0)
  457.                ((setq DrvObj (vlax-invoke FilSys "GetDrive" Drv))
  458.                 (cond
  459.                   ((= (vlax-get DrvObj "IsReady") 0) -1)
  460.                   ((list
  461.                      (/ (vlax-get-property DrvObj "TotalSize") 1000.0)
  462.                      (/ (vlax-get-property DrvObj "FreeSpace") 1000.0)
  463.                      (vlax-get-property DrvObj "DriveType")
  464.                      (vlax-get-property DrvObj "FileSystem")
  465.                      (vlax-get-property DrvObj "SerialNumber")
  466.                      (vlax-get-property DrvObj "ShareName")
  467.                      (vlax-get-property DrvObj "VolumeName")
  468.                    )
  469.                   )
  470.                 )
  471.                )
  472.              )
  473.       )
  474.       (if (EQUAL (TYPE DrvObj) 'vla-object)
  475.         (vlax-release-object DrvObj)
  476.       )
  477.       (vlax-release-object FilSys)
  478.     )
  479.   )
  480.   RetVal
  481. )
  482. (Defun vldos-fileinfo (Drv Key / pos rtn)
  483.   (if (/= (type key) 'STR)
  484.     (setq rtn (vldos-allfileinfo drv))
  485.     (if        (setq pos (vl-position
  486.                     (setq key (strcase key))
  487.                     (list "DATECREATED"              "DATELASTMODIFIED"
  488.                           "DATELASTACCESSED"  "TYPE"
  489.                           "SIZE"              "ATTRIBUTES"
  490.                          )
  491.                   )
  492.         )
  493.       (setq rtn (nth pos (vldos-allfileinfo drv)))
  494.     )
  495.   )
  496.   rtn
  497. )
  498. (Defun vldos-allfileinfo (Fil / FilObj FilSys RetVal)
  499.   (if (setq FilSys (vlax-create-object "Scripting.FileSystemObject"))
  500.     (progn
  501.       (setq
  502.         RetVal (cond
  503.                  ((= (vlax-invoke FilSys "FileExists" Fil) 0) nil)
  504.                  ((setq FilObj (vlax-invoke FilSys "GetFile" Fil))
  505.                   (list
  506.                     (vlax-get FilObj "DateCreated")
  507.                     (vlax-get FilObj "DateLastModified")
  508.                     (vlax-get FilObj "DateLastAccessed")
  509.                     (vlax-get FilObj "Type")
  510.                     (vlax-get FilObj "Size")
  511.                     (vlax-get FilObj "Attributes")
  512.                   )
  513.                  )
  514.                  (T nil)
  515.                )
  516.       )
  517.       (if (= (type FilObj) 'vla-object)
  518.         (vlax-release-object FilObj)
  519.       )
  520.       (vlax-release-object FilSys)
  521.     )
  522.   )
  523.   RetVal
  524. )
  525. ;|  Read all content of a text file into a list (more fast tha AutoLISP read-line)
  526. Syntax: (vldos-readfile FilenameToRead[STRING])
  527.   ARG1: The full path file name to be read. (contain extension)
  528.         Only text file can return good result.
  529. Description:
  530.     Read all content of a text file and convert them into a list
  531. Return Value:
  532. [Success]: List contain text contents line by line
  533. [F a i l]: NIL
  534. |;
  535. (Defun vldos-readfile
  536.        (Fil / string->list FilObj FilPth FilSys OpnFil All)
  537.   (Defun string->list (String / ID Rtn)
  538.     (if        (null (setq ID (vl-string-search "\r\n" String)))
  539.       (setq Rtn (list String))
  540.       (progn
  541.         (while ID
  542.           (setq        Rtn    (cons (substr String 1 ID) Rtn)
  543.                 String (substr String (+ 3 ID))
  544.                 ID     (vl-string-search "\r\n" String)
  545.           )
  546.         )
  547.         (setq Rtn (reverse (cons String Rtn)))
  548.       )
  549.     )
  550.     Rtn
  551.   )
  552.   (if (AND (setq FilPth (findfile Fil))
  553.            (setq FilSys (vlax-create-object "Scripting.FileSystemObject"))
  554.       )
  555.     (progn
  556.       (setq FilObj (vlax-invoke FilSys "GetFile" FilPth)
  557.             OpnFil (vlax-invoke FilObj "OpenAsTextStream" 1 0)
  558.             All           (string->list (vlax-invoke OpnFil "readall"))
  559.       )
  560.       (vlax-invoke OpnFil "Close")
  561.       (vlax-release-object OpnFil)
  562.       (vlax-release-object FilObj)
  563.       (vlax-release-object FilSys)
  564.     )
  565.   )
  566.   All
  567. )
  568. ;|  Write a string list into a text file (more fast tha AutoLISP write-line)
  569. Syntax: (vldos-writefile FileNameString[STRING] ContentStringList[LIST] ModeFlag[BOOLEAN])
  570.         (vldos-writefile FileNameString[STRING] ContentString[STRING] ModeFlag[BOOLEAN])
  571.   ARG1: The filename string
  572.   ARG2: The string or string list to write
  573.   ARG3: The append or overwrite mode flag. nil for append, T for overwrite
  574. Description:
  575.     write a string or a string list into a file
  576. Return Value:
  577. [Success]: The file name string.
  578. [F a i l]: NIL
  579. |;
  580. (Defun vldos-writefile
  581.                        (Fil          TXT            Mode      /
  582.                         list->string            FilObj    FilPth
  583.                         FilSys          OpnFil    Line
  584.                        )
  585.   (Defun list->string (slist / line rtn)
  586.     (if        (= (type slist) 'str)
  587.       (setq rtn slist)
  588.       (progn
  589.         (setq rtn "")
  590.         (foreach line slist
  591.           (if (= rtn "")
  592.             (setq rtn line)
  593.             (setq rtn (strcat rtn "\r\n" line))
  594.           )
  595.         )
  596.       )
  597.     )
  598.     rtn
  599.   )
  600.   (if TXT
  601.     (progn
  602.       (if (and Mode (findfile Fil))
  603.         (vl-file-delete Fil)
  604.       )
  605.       (if (setq FilSys (vlax-create-object "Scripting.FileSystemObject"))
  606.         (progn
  607.           (if (null (setq FilPth (findfile Fil)))
  608.             (setq OpnFil (vlax-invoke-method
  609.                            FilSys "CreateTextFile" Fil 0 0)
  610.             )
  611.             (setq FilObj (vlax-invoke FilSys "GetFile" FilPth)
  612.                   OpnFil (vlax-invoke FilObj "OpenAsTextStream" 8 0)
  613.             )
  614.           )
  615.           (if OpnFil
  616.             (progn
  617. ;;; VBA WinScript data forReading = 1, forWriting = 2, forAppending = 8;
  618. ;;; TristateUseDefault, TristateTrue, TristateFalse (-2, -1, 0)
  619. ;;;TristateUseDefault (-2) Opens the file using the system default.
  620. ;;;TristateTrue (-1) Open the file as Unicode.
  621. ;;;TristateFalse (0) Open the file as ASCII.
  622.               (vlax-invoke OpnFil "Write" (list->string TXT))
  623.               (vlax-invoke OpnFil "Close")
  624.               (vlax-release-object OpnFil)
  625.               (if (= (type FilObj) 'vla-object)
  626.                 (vlax-release-object FilObj)
  627.               )
  628.               (vlax-release-object FilSys)
  629.             )
  630.           )
  631.         )
  632.       )
  633.       (if (setq Filpth (findfile Fil))
  634.         (setq FilPth (vldos-formatpath filpth))
  635.       )
  636.     )
  637.   )
  638.   filpth
  639. )
  640. ;|  Perform Windows browse folder dialog interface
  641. Syntax: (vldos-browsedir PromptString[STRING])
  642.         (vldos-writefile NIL)
  643.   ARG1: The prompt string, if it is nil, use default prompt string of "Select Folder"
  644. Description:
  645.     Display windows browse folder interface sna let user select a folder
  646. Return Value:
  647. [Success]: The selected folder path. If user pick cancel, return NIL
  648. [F a i l]: NIL
  649. |;
  650. (Defun vldos-browsedir (msg / WinShell shFolder path catchit rtn)
  651.   (if (null MSG)
  652.     (setq MSG "Select folder")
  653.   )
  654.   (if (setq winshell (vlax-create-object "Shell.Application"))
  655.     (progn
  656.       (setq shFolder
  657.                      (vlax-invoke-method WinShell 'BrowseForFolder 0 msg 1)
  658.             catchit
  659.                      (vl-catch-all-apply
  660.                        '(lambda        ()
  661.                           (setq shFolder (vlax-get-property shFolder 'self))
  662.                           (setq path (vlax-get-property shFolder 'path))
  663.                         )
  664.                      )
  665.       )
  666.       (vlax-release-object shFolder)
  667.       (vlax-release-object winshell)
  668.       (if (vl-catch-all-error-p catchit)
  669.         (setq rtn nil)
  670.         (setq rtn (vldos-formatpath path))
  671.       )
  672.     )
  673.   )
  674.   rtn
  675. )
  676. ;|  Display windows type message box contain icon and multiple buttons
  677. Syntax: (vldos-msgbox TitleString[STRING] IconType[STRING/REAL] MessageString[STRING] ButtonType[INT])
  678.   ARG1: The title string, if it is nil, use default string of "Message"
  679.   ARG2: The Icon type string or integer. If it is string, only 1st string will be checked.
  680.   ARG3: The message string, if it is nil, use default string of "Message HERE"
  681.   ARG4: Displayed button type integer.
  682. Description:
  683.     Display windows popup message box
  684. Return Value:
  685. [Success]: The button flag that user picked
  686. [F a i l]: NIL
  687. ;;;Buttons
  688. ;;;0  OK
  689. ;;;1  OK and Cancel
  690. ;;;2  Abort, Retry, and Ignore
  691. ;;;3  Yes, No, Cancel
  692. ;;;4  Yes and No
  693. ;;;5  Retry and Cancel
  694. ;;;Icon Types
  695. ;;;16 [X] Stop Mark icon
  696. ;;;32 [?] Question Mark icon
  697. ;;;48 [!] Exclamation Mark icon
  698. ;;;64 [i] Information Mark icon
  699. ;;; Return value for button picked
  700. ;;;1  OK button
  701. ;;;2  Cancel button
  702. ;;;3  Abort button
  703. ;;;4  Retry button
  704. ;;;5  Ignore button
  705. ;;;6  Yes button
  706. ;;;7  No button
  707. |;
  708. (Defun vldos-msgbox (TITLE ICON MSG BTNS / IDT sys BTN)
  709.   (if (setq sys (vlax-get-or-create-object "WScript.Shell"))
  710.     (progn
  711.       (if (not (equal (type TITLE) 'STR))
  712.         (setq TITLE "Message")
  713.       )
  714.       (cond ((null ICON) (setq ICON 64))
  715.             ((= (type ICON) 'STR)
  716.              (setq ICON        (substr (strcase ICON) 1 1)
  717.                    IDT        (list (cons "X" 16)
  718.                               (cons "?" 32)
  719.                               (cons "!" 48)
  720.                               (cons "i" 64)
  721.                         )
  722.                    ICON        (cdr (assoc ICON IDT))
  723.              )
  724.              (if (null ICON)
  725.                (setq ICON 64)
  726.              )
  727.             )
  728.             ((= (type ICON) 'INT)
  729.              (if (null (member ICON (list 16 32 48 64)))
  730.                (setq ICON 64)
  731.              )
  732.              (t (setq ICON 64))
  733.             )
  734.       )
  735.       (if (not (equal (type MSG) 'STR))
  736.         (setq MSG "Message HERE")
  737.       )
  738.       (cond ((null BTNS) (setq BTNS 0))
  739.             ((= (type BTNS) 'INT)
  740.              (if (or (< BTNS 0) (> BTNS 5))
  741.                (setq BTNS 0)
  742.              )
  743.             )
  744.             (t (setq BTNS 0))
  745.       )
  746.       (setq
  747.         BTN (vlax-invoke-method sys 'popup MSG 0 TITLE (+ ICON BTNS))
  748.       )
  749.       (vlax-release-object sys)
  750.     )
  751.   )
  752.   BTN
  753. )
  754. ;|  Recursively searches for instances of a file or files. The function is very similar the
  755.      command prompt's DIR /S command.
  756. Syntax: (vldos-findfile FilenameFullPathString[STRING])
  757.         (vldos-writefile NIL)
  758.   ARG1: The desired file or files. filespec can contain wildcard characters ("*" and "?").
  759.         If filespec is not specified, all files (*.*) in the current directory and in all
  760.         subdirectories are returned.
  761. Description:
  762.     Display windows browse folder interface sna let user select a folder
  763. Return Value:
  764. [Success]: A list of fully qualified filenames.
  765. [F a i l]: NIL
  766. |;
  767. (Defun vldos-findfile (Filename            /                 string->list
  768.                        getallfiles  allfiles         path
  769.                       )
  770.   (Defun string->list (String / ID Rtn)
  771.     (if        (null (setq ID (vl-string-search ";" String)))
  772.       (setq Rtn (list String))
  773.       (progn
  774.         (while ID
  775.           (setq        Rtn    (cons (substr String 1 ID) Rtn)
  776.                 String (substr String (+ 2 ID))
  777.                 ID     (vl-string-search ";" String)
  778.           )
  779.         )
  780.         (setq Rtn (reverse (cons String Rtn)))
  781.       )
  782.     )
  783.     Rtn
  784.   )
  785.   (Defun getallfiles (loc ext / path files rtn)
  786.     (cond
  787.       ((= loc "")
  788.        (foreach        path (string->list (getvar "acadprefix"))
  789.          (setq rtn (append rtn (getallfiles path ext)))
  790.        )
  791.       )
  792.       ((vl-file-directory-p loc)
  793.        (if (null (wcmatch loc "*\"))
  794.          (setq loc (strcat loc "\"))
  795.        )
  796.        (foreach        files (vl-directory-files loc ext)
  797.          (setq rtn (cons (vldos-formatpath (strcat loc files)) rtn))
  798.        )
  799.        (foreach        path (vl-directory-files loc nil -1)
  800.          (if (and (/= path ".")
  801.                   (/= path "..")
  802.              )
  803.            (setq rtn (append rtn (getallfiles (strcat loc path) ext)))
  804.          )
  805.        )
  806.       )
  807.     )
  808.     rtn
  809.   )
  810.   (setq        path         (vldos-formatpath (vl-filename-directory Filename))
  811.         Filename (substr Filename (1+ (strlen path)))
  812.         allfiles (acad_strlsort (getallfiles path filename))
  813.   )
  814.   allfiles
  815. )
  816. ;| Merge 2 TEXT files
  817. Syntax: (vldos-merge MergeBaseFilenameString[STRING] MergeFilenameString[STRING] EraseMergefileFlag[BOOLEAN])
  818.   ARG1: The base file name string
  819.   ARG2: The file that will be merged
  820.   ARG3: The flag if erase the merged file or not.
  821. Description:
  822.     Merge two TEXT files into one file
  823. Return Value:
  824. [Success]: A list of fully qualified filenames.
  825. [F a i l]: NIL
  826. |;
  827. (Defun vldos-merge (file1 File2 Erase / rtn)
  828.   (if (and (setq file1 (findfile file1))
  829.            (setq file2 (findfile file2))
  830.       )
  831.     (progn
  832.       (vldos-writefile file1 (vldos-readfile file2) nil)
  833.       (if Erase
  834.         (vl-file-delete File2)
  835.       )
  836.       (setq rtn (findfile file1))
  837.     )
  838.   )
  839.   rtn
  840. )
  841. ;| Display a HTML file (source codes) or some string in a MS IE window, calling from VLISP
  842. Syntax: (vldos-text->ie ContentString[STRING])
  843.   ARG1: The string or string list to be displayed in IE Window
  844. Description:
  845.     Calling within Visual LISP, send string data into a new MS IE window
  846. Return Value:
  847. [Success]: The MS IE window with string(s)
  848. [F a i l]: NIL
  849. |;
  850. (Defun vldos-text->ie (TXT / list->string ie ln doc)
  851.   (if (= (type TXT) 'STR)
  852.     (setq TXT (list TXT))
  853.   )
  854.   (if (setq ie (vlax-create-object "InternetExplorer.Application"))
  855.     (progn
  856.       (vlax-put-property ie 'menubar 0)
  857.       (vlax-put-property ie 'toolbar 0)
  858.       (vla-put-visible ie t)
  859.       (vlax-invoke-method ie 'navigate "about:blank")
  860.       (setq doc (vlax-get-property ie 'document))
  861.       (foreach ln TXT
  862.         (vlax-invoke-method doc 'writeln ln "")
  863.       )
  864.       (vlax-invoke-method doc 'close)
  865.       (vlax-release-object doc)
  866.       (vlax-release-object ie)
  867.     )
  868.   )
  869. )
  870. ;| call the windows date/time setting dialog from VLISP
  871. Syntax: (vldos-time)
  872. Description:
  873.     Calling within Visual LISP, display the windows date/time setting window
  874. Return Value:
  875. [Success]: The windows date/time setting window
  876. [F a i l]: NIL
  877. |;
  878. (Defun vldos-time (/ sys)
  879.   (if (setq sys (vlax-get-or-create-object "Shell.Application"))
  880.     (progn
  881.       (vlax-invoke-method sys 'settime)
  882.       (vlax-release-object sys)
  883.     )
  884.   )
  885. )

评分

参与人数 1威望 +1 D豆 +5 收起 理由
xshrimp + 1 + 5

查看全部评分

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 488个

财富等级: 日进斗金

发表于 2004-1-9 23:23:23 | 显示全部楼层
加分了,
不过我没细看,有一部分秋峰贴过.
其实只要找一下"Scripting.FileSystemObject"的方法,基本就可以写出来了.
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1915个

财富等级: 堆金积玉

发表于 2004-1-11 19:57:01 | 显示全部楼层
像楼上说的"Scripting.FileSystemObject"方法的帮助在哪能找到,或者介绍一下什么书中有相关的介绍,还有类似的,比如系统共用对话框(文件打开、目录浏览等等)在vlisp中如何使用?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2004-1-12 13:22:42 | 显示全部楼层
可以在WindowxXP系统的
C:\Program Files\Microsoft Visual Studio\Common\IDE\IDE98\MSE\2052
中找到
VBSCRIP5.CHM
ASP.CHM
JSCRIPT5.CHM
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-25 10:37 , Processed in 0.400858 second(s), 37 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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