Jump to content

Copy file to current directory


J-LYLE

Recommended Posts

Im wanting to be able to copy a file from a known location to the directory of the file i have open is in(will not always be the same), but im not sure where to start. Any advice?

Thanks.

Link to comment
Share on other sites

In case i phrased the question very poorly. I want to copy 1.dwg from..Ex: C:\ACAD\1.dwg to the directory that the file i have open is in. (..\Refs).

I would be thankfull for any sugestions.

Link to comment
Share on other sites

This may help, it will open Windows Explorer in the folder of the dwg you have open.

(startapp "explorer" (strcat "/e,"(getvar "dwgprefix")))

Link to comment
Share on other sites

From Developer Help:

 

vl-file-copy

 

 

Copies or appends the contents of one file to another file

 

(vl-file-copy source-file destination-file [append])

Copy or append the contents of one file to another file. The vl-file-copy function will not overwrite an existing file; it will only append to it.

 

Arguments

 

source-file

A string naming the file to be copied. If you do not specify a full path name, vl-file-copy looks in the AutoCAD default drawing directory.

 

destination-file

A string naming the destination file. If you do not specify a path name, vl-file-copy writes to the AutoCAD default drawing directory.

 

append

If specified and not nil, source-file is appended to destination-file (that is, copied to the end of the destination file).

 

Return Values

 

An integer, if the copy was successful; otherwise nil.

 

Some typical reasons for returning nil are

 

source-file is not readable

source-file is a directory

append? is absent or nil and destination-file exists

destination-file cannot be opened for output (that is, it is an illegal file name or a write-protected file)

source-file is the same as destination-file

Examples

 

Copy autoexec.bat to newauto.bat:

 

_$ (vl-file-copy "c:/autoexec.bat"

"c:/newauto.bat")

1417

Copy test.bat to newauto.bat:

 

_$ (vl-file-copy "c:/test.bat"

"c:/newauto.bat")

nil

The copy fails because newauto.bat already exists, and the append argument was not specified.

 

Repeat the previous command, but specify append:

 

_$ (vl-file-copy "c:/test.bat"

"c:/newauto.bat" T)

185

The copy is successful because T was specified for the append argument.

Link to comment
Share on other sites

Maby I missunderstood, what I thought would happen is that when I ran the lisp it would copy the file "W0114-150.dwg" into the directory of the drawing I had open at the time, but unfortunatly it did nothing. Can anyone please offer some advice on "vl-file-copy".

 

 

(vl-file-copy "C:/ACAD/Lisp/testLISPFORNEWWDSPULLDOWN/W0114-150.dwg" "" T)

Link to comment
Share on other sites

you've only provided one file name.

It's looking for a source file AND a destination file

 

oops, you did provide two but the second one is ""

Link to comment
Share on other sites

Thanks for the quick reply.

 

What I was shooting for was not to have to give it a destination I want the file name to be the same and the destination to be what ever directory the open drawing im working in is in. Is that possiable with this function or should I try to figure it out another way.?

Link to comment
Share on other sites

For Ex: I will be working on

h:\00001\drawing1.dwg or

h:\00002\drawing1.dwg or

h:\00003\drawing1.dwg...ect...

and want to copy c:\drawingZ.dwg to

h:\00001\drawingZ.dwg or

h:\00002\drawingZ.dwg...ect....

 

The destination will change depending on what job/file I am working on. My plan is that after I figure out how to copy the file this way to also have this file xrefed in to the file I am working on to add certain details for specific conditions on jobs. The xref needs to be in the job folder and xrefed from their incase of special changes specific to that job, but I only want to add it to the job if I need it.

Link to comment
Share on other sites

give this a try j-lyle,

 

(defun c:test (/ curr_dir  foldr&flname_2copy)
  (vl-load-com)
  (setq foldr&flname_2copy
   '("C:\\Documents and Settings\\wizman\\My Documents\\"	[color="blue"];<<< input here folder path of source[/color]
     "Drawing1.dwg"		                                [color="Blue"];<<< input here filename to be copied[/color]
    )
  ) ;_ end_setq
  (if (findfile (apply 'strcat foldr&flname_2copy))
     (if (findfile (strcat (getvar "dwgprefix") (cadr foldr&flname_2copy)))
 (alert "\n File Exists in Destination Folder")
 (progn
    (setq curr_dir (strcat (getvar "dwgprefix") (cadr foldr&flname_2copy)))
    (vl-file-copy (apply 'strcat foldr&flname_2copy) curr_dir)
    (prompt (strcat (strcase (cadr foldr&flname_2copy))
		    " copied to "
		    (strcase (getvar "dwgprefix"))
	    ) ;_ end_strcat
    ) ;_ end_prompt
 ) ;_ end_progn
     ) ;_ end_if
     (alert "\n Source File Does not Exist")
  ) ;_ end_if
  (princ)
) ;_ end_defun
(princ)

Link to comment
Share on other sites

  • 4 months later...
  • 10 years later...
 (setq foldr&flname_2copy
   '("C:\\Documents and Settings\\wizman\\My Documents\\"	[color="blue"];<<< input here folder path of source[/color]
     "Drawing1.dwg"	

SOrry!! Help me!!!!

I want file name is input from editbox!!!

thanks!!!

editbox.JPG

Link to comment
Share on other sites

On 3/21/2008 at 4:21 AM, wizman said:

give this a try j-lyle,

 

 


(defun c:test (/ curr_dir  foldr&flname_2copy)
  (vl-load-com)
  (setq foldr&flname_2copy
   '("C:\\Documents and Settings\\wizman\\My Documents\\"	[color="blue"];<<< input here folder path of source[/color]
     "Drawing1.dwg"		                                [color="Blue"];<<< input here filename to be copied[/color]
    )
  ) ;_ end_setq
  (if (findfile (apply 'strcat foldr&flname_2copy))
     (if (findfile (strcat (getvar "dwgprefix") (cadr foldr&flname_2copy)))
 (alert "\n File Exists in Destination Folder")
 (progn
    (setq curr_dir (strcat (getvar "dwgprefix") (cadr foldr&flname_2copy)))
    (vl-file-copy (apply 'strcat foldr&flname_2copy) curr_dir)
    (prompt (strcat (strcase (cadr foldr&flname_2copy))
		    " copied to "
		    (strcase (getvar "dwgprefix"))
	    ) ;_ end_strcat
    ) ;_ end_prompt
 ) ;_ end_progn
     ) ;_ end_if
     (alert "\n Source File Does not Exist")
  ) ;_ end_if
  (princ)
) ;_ end_defun
(princ)
 

SOrry!! Help me!!!!

I want file name is input from editbox!!!

thanks!!!

 

Link to comment
Share on other sites

  • 3 years later...

I know this is an old topic. How could I change this from a file to a folder with everything in it? I thought i would swap out the file name and extension to a (*

*), but not so much. Thank you for any pointers.

 

(defun c:test (/ curr_dir  foldr&flname_2copy)
;;https://www.cadtutor.net/forum/topic/1138-copy-file-to-current-directory/
  (vl-load-com)
  (setq foldr&flname_2copy
   '("C:\\Documents and Settings\\wizman\\My Documents\\"	;;[color="blue"];<<< input here folder path of source[/color]
;;     "Drawing1.dwg"		                                ;;[color="Blue"];<<< input here filename to be copied[/color]

     "*.*" ;;assuming for all folders and files

    )
  ) ;_ end_setq
  (if (findfile (apply 'strcat foldr&flname_2copy))
     (if (findfile (strcat (getvar "dwgprefix") (cadr foldr&flname_2copy)))
 (alert "\n Folder and Files Exist in Destination Folder")
 (progn
    (setq curr_dir (strcat (getvar "dwgprefix") (cadr foldr&flname_2copy)))
    (vl-file-copy (apply 'strcat foldr&flname_2copy) curr_dir)
    (prompt (strcat (strcase (cadr foldr&flname_2copy))
		    " copied to "
		    (strcase (getvar "dwgprefix"))
	    ) ;_ end_strcat
    ) ;_ end_prompt
 ) ;_ end_progn
     ) ;_ end_if
     (alert "\n Source Folder and Files Do not Exist")
  ) ;_ end_if
  (princ)
) ;_ end_defun
(princ)






 

Link to comment
Share on other sites

Ok the answer is old fashioned DOS XCOPY, you can run windows CMD using (command "shell" "xcopydoscommand") so google xcopy as 1st step.

 

Edited by BIGAL
Link to comment
Share on other sites

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...