muck Posted September 21, 2010 Share Posted September 21, 2010 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, Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 21, 2010 Share Posted September 21, 2010 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)) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 27, 2010 Share Posted September 27, 2010 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. Quote Link to comment Share on other sites More sharing options...
muck Posted September 29, 2010 Author Share Posted September 29, 2010 (edited) I got the above lisp code working but how would I show path & file names in my list? Thank you, Edited September 29, 2010 by muck Quote Link to comment Share on other sites More sharing options...
Ahankhah Posted September 29, 2010 Share Posted September 29, 2010 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 Quote Link to comment Share on other sites More sharing options...
Ahankhah Posted September 29, 2010 Share Posted September 29, 2010 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)) ) Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 29, 2010 Share Posted September 29, 2010 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). 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! Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 29, 2010 Share Posted September 29, 2010 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)) 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.