+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
  1. #1
    Super Member MarcoW's Avatar
    Computer Details
    MarcoW's Computer Details
    Operating System:
    Microsoft Windows 7 Pro 64-bit
    Computer:
    A black one
    CPU:
    Intel Xeon E5520 Quad Core
    RAM:
    8 GB
    Graphics:
    NVIDIA Quadro FX 580 - 512MB
    Primary Storage:
    300 GB 10000 RPM
    Using
    AutoCAD 2011
    Join Date
    Apr 2009
    Location
    The Netherlands
    Posts
    599

    Default How to copy a list of files from one directory to another?

    Registered forum members do not see this ad.

    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:

    Code:
     
    (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

  2. #2
    Super Member MarcoW's Avatar
    Computer Details
    MarcoW's Computer Details
    Operating System:
    Microsoft Windows 7 Pro 64-bit
    Computer:
    A black one
    CPU:
    Intel Xeon E5520 Quad Core
    RAM:
    8 GB
    Graphics:
    NVIDIA Quadro FX 580 - 512MB
    Primary Storage:
    300 GB 10000 RPM
    Using
    AutoCAD 2011
    Join Date
    Apr 2009
    Location
    The Netherlands
    Posts
    599

    Default

    AlanJT's subroutine might be of help??... but I do not know how to use it...

    Code:
     
    ;;; 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

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,418

    Default

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

    Code:
    (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)
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  4. #4
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,199

    Default

    Quote Originally Posted by MarcoW View Post
    AlanJT's subroutine might be of help??... but I do not know how to use it...

    Code:
     
    ;;; 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.
    DropBox
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  5. #5
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,199

    Default

    Quote Originally Posted by Lee Mac View Post
    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).

    Code:
    (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.
    DropBox
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,418

    Default

    Quote Originally Posted by alanjt View Post
    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.'
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  7. #7
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,199

    Default

    Quote Originally Posted by Lee Mac View Post
    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.
    DropBox
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  8. #8
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,418

    Default

    Quote Originally Posted by alanjt View Post
    Oops, missed that. I think I also have one similar to the one you posted in the subroutine thread I started.
    No worries
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  9. #9
    Super Member MarcoW's Avatar
    Computer Details
    MarcoW's Computer Details
    Operating System:
    Microsoft Windows 7 Pro 64-bit
    Computer:
    A black one
    CPU:
    Intel Xeon E5520 Quad Core
    RAM:
    8 GB
    Graphics:
    NVIDIA Quadro FX 580 - 512MB
    Primary Storage:
    300 GB 10000 RPM
    Using
    AutoCAD 2011
    Join Date
    Apr 2009
    Location
    The Netherlands
    Posts
    599

    Default

    Quote Originally Posted by Lee Mac View Post
    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).

    Code:
    (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?

    Code:
     
     (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)

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,418

    Default

    Registered forum members do not see this ad.

    Does this directory exist?

    Code:
    nPrinterStyleSheetDir
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. LIST to TXT files
    By Coosbaylumber in forum AutoCAD General
    Replies: 5
    Last Post: 11th Nov 2009, 10:48 pm
  2. Trouble setting up drawing files directory in My Documents
    By berol in forum AutoCAD Beginners' Area
    Replies: 4
    Last Post: 7th May 2009, 04:29 am
  3. COPY Command and list of points ?
    By chavlji in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 7th Mar 2009, 02:41 pm
  4. Copy file to current directory
    By J-LYLE in forum AutoLISP, Visual LISP & DCL
    Replies: 12
    Last Post: 21st Aug 2008, 08:24 am
  5. Opening Files from same directory?
    By Ste1978 in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 31st May 2006, 12:51 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts