MarcoW Posted March 6, 2010 Share Posted March 6, 2010 Hello, I have a need for following lisp: when executed it should check where the current CTB files are stored (with (getenv "PrinterStyleSheetDir"))). It should copy all the *.ctb files into another folder that allready exists: "c:\program files\MarcoW\". This is what I have found to be working for 1 file, in this case a text file: (vl-file-copy (findfile "atextfile.txt") "c:\\atextfile.txt") So I figured, I should make a list out of * .ctb files in the current PrinterStyleSheetDir. That is what I do not know how to do. All I find is getfiled functions. Because that prompts to select file, I cannot use it. The "findfile" function uses the support file search paths so that won't work either. Do you know a solution? Thanks in advance! My attempt so far: (defun c:CopyCtb ( / ); localizing later (setq ; get current directory for *.ctb files cPrinterStyleSheetDir (getenv "PrinterStyleSheetDir") ; get current directory program files cProgramFiles (getenv "programfiles") ; the new *.ctb files directory nPrinterStyleSheetDir (strcat cProgramFiles "\MarcoW\Plotter\") ); end of setq ; here the part to get all CTB files in the current "env PrinterStyleSheetDir" (princ)); end of defun Quote Link to comment Share on other sites More sharing options...
MarcoW Posted March 6, 2010 Author Share Posted March 6, 2010 AlanJT's subroutine might be of help??... but I do not know how to use it... ;;; Copy entire contents of directory to new location (subfolders included) ;;; #Source - source folder to copy ;;; #Dest - destination directory (will be created if doesn't exist) ;;; Alan J. Thompson, 10.06.09 (defun AT:XCopyDirectory (#Source #Dest / *error* #Scr) (setq *error* (lambda (x) (and #Scr (vlax-release-object #Scr)))) (cond ((findfile #Source) (setq #Scr (vlax-get-or-create-object "WScript.Shell")) (vlax-invoke-method #Scr "Run" (strcat "XCopy " #Source " /E /H /Q /Y /I " #Dest) 0) ) ) ;_ cond (*error* nil) ) ;_ defun Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 6, 2010 Share Posted March 6, 2010 Not as fancy as Alan's use of the Windows Script Host, but this is one way to copy all files in a directory (not including subdirectories). (defun CopyFiles (dir typ dest) (vl-load-com) (foreach file (vl-directory-files dir typ 1) (vl-file-copy (strcat dir file) (strcat dest file))) (princ)) dir : Source Directory (use double backslashes) typ : type of files (DOS pattern, eg "*.dwg") dest : Destination Directory (must be valid) Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 6, 2010 Share Posted March 6, 2010 AlanJT's subroutine might be of help??... but I do not know how to use it... ;;; Copy entire contents of directory to new location (subfolders included) ;;; #Source - source folder to copy ;;; #Dest - destination directory (will be created if doesn't exist) ;;; Alan J. Thompson, 10.06.09 (defun AT:XCopyDirectory (#Source #Dest / *error* #Scr) (setq *error* (lambda (x) (and #Scr (vlax-release-object #Scr)))) (cond ((findfile #Source) (setq #Scr (vlax-get-or-create-object "WScript.Shell")) (vlax-invoke-method #Scr "Run" (strcat "XCopy " #Source " /E /H /Q /Y /I " #Dest) 0) ) ) ;_ cond (*error* nil) ) ;_ defun It will copy everything within one directory (including sub-directories) to another. If the destination does not exist, it will be created. I used XCopy to easily copy all sub-directories and WScript to avoid any annoying Dos windows. Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 6, 2010 Share Posted March 6, 2010 Not as fancy as Alan's use of the Windows Script Host, but this is one way to copy all files in a directory (not including subdirectories). (defun CopyFiles (dir typ dest) (vl-load-com) (foreach file (vl-directory-files dir typ 1) (vl-file-copy (strcat dir file) (strcat dest file))) (princ)) dir : Source Directory (use double backslashes) typ : type of files (DOS pattern, eg "*.dwg") dest : Destination Directory (must be valid) I'm pretty sure vl-file-copy will fail if it can't find the destination directory. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 6, 2010 Share Posted March 6, 2010 I'm pretty sure vl-file-copy will fail if it can't find the destination directory. Exactly, which is why I said the destination directory 'must be valid.' Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 6, 2010 Share Posted March 6, 2010 Exactly, which is why I said the destination directory 'must be valid.' Oops, missed that. I think I also have one similar to the one you posted in the subroutine thread I started. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 6, 2010 Share Posted March 6, 2010 Oops, missed that. I think I also have one similar to the one you posted in the subroutine thread I started. No worries Quote Link to comment Share on other sites More sharing options...
MarcoW Posted March 7, 2010 Author Share Posted March 7, 2010 Not as fancy as Alan's use of the Windows Script Host, but this is one way to copy all files in a directory (not including subdirectories). (defun CopyFiles (dir typ dest) (vl-load-com) (foreach file (vl-directory-files dir typ 1) (vl-file-copy (strcat dir file) (strcat dest file))) (princ)) dir : Source Directory (use double backslashes) typ : type of files (DOS pattern, eg "*.dwg") dest : Destination Directory (must be valid) I am about to explode Why is this not working? (vl-load-com) (setq cPrinterStyleSheetDir (getenv "PrinterStyleSheetDir") cProgramFiles (getenv "ProgramFiles") nPrinterStyleSheetDir (strcat cProgramFiles "\\MarcoW\\Plotter\\") (foreach file (vl-directory-files cPrinterStyleSheetDir "*.ctb" 1) (vl-file-copy (strcat cPrinterStyleSheetDir file) (strcat nPrinterStyleSheetDir file))) (princ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 7, 2010 Share Posted March 7, 2010 Does this directory exist? nPrinterStyleSheetDir Quote Link to comment Share on other sites More sharing options...
MarcoW Posted March 7, 2010 Author Share Posted March 7, 2010 yes it does but maybe i should make it a bit simple..? like c:\\marcow\\ ? edit: yes this works.. (vl-load-com) (foreach file (vl-directory-files "c:\\map1\\" "*.txt" 1) (vl-file-copy (strcat "c:\\map1\\" file) (strcat "c:\\map2\\" file))) (princ) I must have made a mistake... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 7, 2010 Share Posted March 7, 2010 I see your problem - Bear in mind that (getenv "PrinterStyleSheetDir") Will not end with "\\", and when you are concatenating it with the file, it needs a "\\" to make it a valid filepath. Quote Link to comment Share on other sites More sharing options...
MarcoW Posted March 7, 2010 Author Share Posted March 7, 2010 You are right :-) This is working now: (vl-load-com) (setq cPrinterStyleSheetDir [b][color=red](strcat[/color][/b] (getenv "PrinterStyleSheetDir") [b][color=red]"\\")[/color][/b]cProgramFiles (getenv "ProgramFiles") nPrinterStyleSheetDir (strcat cProgramFiles " Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 7, 2010 Share Posted March 7, 2010 You're welcome Marco Quote Link to comment Share on other sites More sharing options...
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.