Author Topic: Copy Folder gives error  (Read 2841 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Copy Folder gives error
« on: February 27, 2016, 05:16:23 AM »
I am trying to copy a folder using vlax-invoke but gives error
Code - Auto/Visual Lisp: [Select]
  1.   (vl-file-directory-p "B:\\Caplus_Standars\\AutoCAD\\CAPlus-Menu")
  2.   (progn
  3.     (setq FSO (vlax-create-object "Scripting.FileSystemObject"))
  4.     (vlax-invoke FSO "CopyFolder" "B:\\Caplus_Standars\\AutoCAD\\CAPlus-Menu" "C:\\Caplus_Standars\\AutoCAD\\CAPlus-Menu" :vlax-true)
  5.     ))

Error
Code - Auto/Visual Lisp: [Select]
  1. ; error: Exception occurred
Thanks

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Copy Folder gives error
« Reply #1 on: February 27, 2016, 11:10:32 AM »
Couple guesses without benefit of coffee or sitting down with AutoCAD ...

1. You should use vars to host the source & target folder names to prevent typos.
2. When using vlax-invoke arguments that visual basic expects as vbTrue & vbFalse are instead passed as -1 and 0 respectively.
3. Operations like CopyFolder are not generally instantaneous (likely spawns an asynchronous operation). Yet program program flow merrily continues suggesting the CopyFolder call is complete. So it's quite possible you're releasing the object before it has completed its task. If that proves the case one might have to write a function that stays in a loop while validating folder replication (c/w timeout so an infinite loop is thwarted) before allowing the release of the FSO variable.
4. Like I said, all wild assed guesses.
5. Off to find coffee ...
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Copy Folder gives error
« Reply #2 on: February 27, 2016, 01:57:53 PM »
You also try THIS.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Copy Folder gives error
« Reply #3 on: February 27, 2016, 03:18:07 PM »
There is also a non-FSO version which may be found here: Copy Folder.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Copy Folder gives error
« Reply #4 on: February 27, 2016, 08:54:39 PM »
Couple guesses without benefit of coffee or sitting down with AutoCAD ...

1. You should use vars to host the source & target folder names to prevent typos.
2. When using vlax-invoke arguments that visual basic expects as vbTrue & vbFalse are instead passed as -1 and 0 respectively.
3. Operations like CopyFolder are not generally instantaneous (likely spawns an asynchronous operation). Yet program program flow merrily continues suggesting the CopyFolder call is complete. So it's quite possible you're releasing the object before it has completed its task. If that proves the case one might have to write a function that stays in a loop while validating folder replication (c/w timeout so an infinite loop is thwarted) before allowing the release of the FSO variable.
4. Like I said, all wild assed guesses.
5. Off to find coffee ...

6- Thanks for your reply
7- Have a nice coffee   ;-)

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Copy Folder gives error
« Reply #5 on: February 27, 2016, 08:55:40 PM »
You also try THIS.
Thanks ronjonp I'll give this a try.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Copy Folder gives error
« Reply #6 on: February 27, 2016, 08:57:57 PM »
There is also a non-FSO version which may be found here: Copy Folder.
I need to overwrite the exist. and version with overwrite not working

I am using CAD 2014 Win 64.

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Copy Folder gives error
« Reply #7 on: February 28, 2016, 06:49:00 AM »
Do you have full write-permissions for the target directory?

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Copy Folder gives error
« Reply #8 on: February 28, 2016, 10:21:07 AM »
Do you have full write-permissions for the target directory?
yes I have and tested by creating new folder the folder created.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Copy Folder gives error
« Reply #9 on: February 29, 2016, 03:03:57 AM »
You also try THIS.

Working as a charm.  ;-) 

ChrisCarlson

  • Guest
Re: Copy Folder gives error
« Reply #10 on: February 29, 2016, 07:49:54 AM »
How big is the file?

Might propose something along these lines to give a progress bar.

Quote
(setq itcopied (vl-cmdf "SHELL" (strcat "\"esentutl /y \"" networkfile \"" /d \"" fullname \""/o \"")))

https://www.theswamp.org/index.php?topic=50479.msg556043#msg556043

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Copy Folder gives error
« Reply #11 on: February 29, 2016, 09:17:08 AM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Copy Folder gives error
« Reply #12 on: March 01, 2016, 01:04:27 AM »
How big is the file?

Might propose something along these lines to give a progress bar.

Quote
(setq itcopied (vl-cmdf "SHELL" (strcat "\"esentutl /y \"" networkfile \"" /d \"" fullname \""/o \"")))

https://www.theswamp.org/index.php?topic=50479.msg556043#msg556043

The file is not more 500KB