Jump to content

Recommended Posts

Posted

Wat is the function to copy one folder to another folder? and how?

Posted

Hi,

 

AFAIK there's no built in AutoLISP function to copy a folder, but you can use the "Scripting.FilesystemObject" ActiveX.

 

Here's an example, source and target arguments are strings (folders full pathes):

 

(defun CopyFolder (source target / fso)
 (vl-load-com)
 (setq FSO (vlax-create-object "Scripting.FilesystemObject"))
 (if (= -1 (vlax-invoke fso 'folderexists source))
   (vlax-invoke fso 'copyfolder source target)
 )
 (vlax-release-object fso)
)

Posted
Hi,

 

AFAIK there's no built in AutoLISP function to copy a folder, but you can use the "Scripting.FilesystemObject" ActiveX.

 

Here's an example, source and target arguments are strings (folders full pathes):

 

(defun CopyFolder (source target / fso)
 (vl-load-com)
 (setq FSO (vlax-create-object "Scripting.FilesystemObject"))
 (if (= -1 (vlax-invoke fso 'folderexists source))
   (vlax-invoke fso 'copyfolder source target)
 )
 (vlax-release-object fso)
)

 

 

Can you explain than what it is doing?

Posted

I'm not sure there is much more to explain - the code creates an instance of the FileSystemObject, and uses the CopyFolder method associated with that object.

Posted

Perhaps another way to do it, without using the FileSystemObject:

 

;; CopyFolder (Lee Mac)
;; Copies the contents of a folder (and subfolders).
;; Source  ~  [sTR] Source Directory e.g. "C:\\Directory"
;; Dest    ~  [sTR] Destination Directory (will be created if non-existent).

(defun CopyFolder (Source Dest)
 (vl-load-com)

 (vl-mkdir Dest)
 (mapcar
   (function
     (lambda ( file )
       (vl-file-copy
         (strcat Source "\\" file) (strcat Dest "\\" file))))
   (vl-directory-files Source nil 1))

 (mapcar
   (function
     (lambda ( directory )
       (CopyFolder
         (strcat Source "\\" directory) (strcat Dest "\\" directory))))

   (cddr (vl-directory-files Source nil -1))))

Posted
Perhaps another way to do it, without using the FileSystemObject:

 

;; CopyFolder (Lee Mac)
;; Copies the contents of a folder (and subfolders).
;; Source  ~  [sTR] Source Directory e.g. "C:\\Directory"
;; Dest    ~  [sTR] Destination Directory (will be created if non-existent).

(defun CopyFolder (Source Dest)
 (vl-load-com)

 (vl-mkdir Dest)
 (mapcar
   (function
     (lambda ( file )
       (vl-file-copy
         (strcat Source "\\" file) (strcat Dest "\\" file))))
   (vl-directory-files Source nil 1))

 (mapcar
   (function
     (lambda ( directory )
       (CopyFolder
         (strcat Source "\\" directory) (strcat Dest "\\" directory))))

   (cddr (vl-directory-files Source nil -1))))

 

Thanks for your effort.

This is i want.

Posted
Thanks for your effort.

This is i want.

 

You're welcome, but using the FileSystemObject is probably a lot faster.

Posted
Thanks for your effort.

This is i want.

 

I know very well and i am using always mapcar and lambda functions.

But you used "Function" inbetween mapcar and lambda. Can you explain wat it is doing there?

Posted
I know very well and i am using always mapcar and lambda functions.

But you used "Function" inbetween mapcar and lambda. Can you explain wat it is doing there?

 

It notifies the interpreter that the lambda expression is to be treated as a function argument for the mapcar function. It has a slight performance improvement over using a quoted expression.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...