muthu123 Posted April 18, 2010 Posted April 18, 2010 Wat is the function to copy one folder to another folder? and how? Quote
gile Posted April 18, 2010 Posted April 18, 2010 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) ) Quote
muthu123 Posted April 18, 2010 Author Posted April 18, 2010 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? Quote
Lee Mac Posted April 18, 2010 Posted April 18, 2010 See here Muthu: http://msdn.microsoft.com/en-us/library/xbfwysex%28v=VS.85%29.aspx Quote
muthu123 Posted April 18, 2010 Author Posted April 18, 2010 See here Muthu: http://msdn.microsoft.com/en-us/library/xbfwysex%28v=VS.85%29.aspx Dear lee, I can't understand VBA Codes. Can you explain in VLISP code? Quote
Lee Mac Posted April 18, 2010 Posted April 18, 2010 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. Quote
Lee Mac Posted April 18, 2010 Posted April 18, 2010 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)))) Quote
muthu123 Posted April 18, 2010 Author Posted April 18, 2010 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. Quote
Lee Mac Posted April 18, 2010 Posted April 18, 2010 Thanks for your effort.This is i want. You're welcome, but using the FileSystemObject is probably a lot faster. Quote
muthu123 Posted April 18, 2010 Author Posted April 18, 2010 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? Quote
alanjt Posted April 18, 2010 Posted April 18, 2010 Here's one I did... http://www.cadtutor.net/forum/showpost.php?p=305105&postcount=62 Quote
Lee Mac Posted April 18, 2010 Posted April 18, 2010 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. Quote
Recommended Posts
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.