Jump to content

Using Batch Processing to create a *.dwg File List?


muck

Recommended Posts

I am trying to write a batch program that lists the current directory of files that end in *.dwg

into a file on my C drive.

I have used the following code:

dir *.dwg /b >C:FileListing.txt

start notepad C:FileListing.txt

 

This code only gives file names in the current directory.

I need to have a list of path and file names in the file FileListing.txt

Is there a way to do that without including subdirectories??

 

Thank you,

Link to comment
Share on other sites

Edit: I understand you're using Windows Batch File... but I have LISP (sorry, not that familiar with batch files).

 

Have you looked into the vl-directory-files function?

 

I use this to list all drawings found within the active directory, you *might* be able to pull a piece from it for your use:

 

(defun c:ShowDWGFiles  (/ dwgList)
 (vl-load-com)
 (terpri)
 (if (setq dwgList (vl-directory-files (getvar 'dwgprefix) "*.dwg" 1))
    (progn
      (prompt "\nListing drawings found in active directory... ")
      (terpri)
      (textpage)
      (foreach file  dwgList
        (prompt (strcat "\n  >>  " file)))))
 (terpri)
 (princ))

Link to comment
Share on other sites

There is a simple way to add the path to an existing txt file list open the txt file in Word use search replace ^p with C:\mypath\andsubdir1\andsubdir2^p

 

the ^p means replace the end of line character so it adds the path to the start of the next line.

 

I would go the renderman way though then you don,t have to edit.

Link to comment
Share on other sites

muck,

just change the 10th line of RenderMan's code from:

(prompt (strcat "\n  >>  " file))

to:

(prompt (strcat "\n" (getvar 'dwgprefix) file))

Of course, it returns the list of files in the current directory of your AutoCAD.

 

Mehrdad

www.irancad.com

Link to comment
Share on other sites

Here is the code to write informations into a file.

 

(defun c:ShowDWGFiles (/ dwgList)
   (vl-load-com)
   (terpri)
   (if (setq dwgList (vl-directory-files (getvar 'dwgprefix) "*.*" 1))
       (progn (setq file-id (open "C:\\FileListing.txt" "w"))
              (princ "\nListing drawings found in active directory... " file-id)
              (princ "\n" file-id)
              (foreach file dwgList
                  (princ (strcat "\n" (getvar 'dwgprefix) file) file-id)
              )
       )
   )
   (setq file-id (close file-id))
)

Link to comment
Share on other sites

muck,

just change the 10th line of RenderMan's code from:

(prompt (strcat "\n >> " file))

to:

(prompt (strcat "\n" (getvar 'dwgprefix) file))

 

 

That repeatedly queries the dwgprefix system variable (unneccessarily). :ouch:

 

Instead, you could simply use this:

 

(defun c:ShowDWGFiles  (/ path dwgList)
 (vl-load-com)
 (terpri)
 (if (setq dwgList (vl-directory-files (setq path (getvar 'dwgprefix)) "*.dwg" 1))
    (progn
      (prompt "\nListing drawings found in active directory... ")
      (terpri)
      (textpage)
      (foreach file  dwgList
        (prompt (strcat "\n  >>  " path file)))))
 (terpri)
 (princ))

 

 

Hope this helps! 8)

Link to comment
Share on other sites

Write list to file... then show it:

 

(defun c:WriteDWGFiles  (/ path dwgList txtPath f)
 (vl-load-com)
 (if (setq dwgList (vl-directory-files
     (setq path (getvar 'dwgprefix))
     "*.dwg"
     1))
   (progn
 (if (findfile (setq txtPath (strcat path "_Drawings.txt")))
   (vl-file-delete txtPath))
 (setq f (open txtPath "w"))
 (write-line "\nDrawings found in active directory... \n" f)
 (foreach dwg  dwgList
   (write-line (strcat path dwg) f))
 (close f)
 (startapp "notepad" txtPath)))
 (princ))

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