I've used modified versions of this code for batch processing with success. Here, it has been adjusted for your needs:
;Batcher_XRef.lsp
;Description: Removes all XRefs in Batch Process applied to all dwgs in Specified Directory.
;Tip: Run this from a drawing that is NOT in the Specified Directory.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Start Main Prog
(defun c:Batcher_XRef (/ wutdir wutfiles scrfile n2 scrline)
(vl-load-com)
(setq wutdir (LM:browseforfolder "Select directory to process:" "C:\\" 512));;;<--Specified Directory
(setq wutfiles (vl-directory-files wutdir "*.dwg"))
(setq scr_name (strcat wutdir "\\scrfile.scr"))
(setq scrfile (open scr_name "w"))
(close scrfile)
(setq scrfile (open scr_name "a"))
(foreach n wutfiles
(setq n2 (strcat "\""wutdir "\\" n "\""))
(setq n2 (vl-string-translate "\\" "\\" n2))
(setq scrline (strcat "open" " " n2 " " "(load\"Batcher_XRef\")" " " "LISP_Functions" " " "qsave" " " "close"))
(write-line scrline scrfile)
(princ)
)
(close scrfile)
(command "script" scr_name)
(princ "\n***Batch complete.***")
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Start LISP Functions
(defun c:LISP_Functions ()
(command "_.-xref" "detach" "*");;;<--LISP Function - Change to your neeeds
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Start Browse for Folder
;; THANKYOU Mr. M!
;; Browse for Folder - Lee Mac
;; Displays a dialog prompting the user to select a folder.
;; msg - [str] message to display at top of dialog
;; dir - [str] [optional] root directory (or nil)
;; bit - [int] bit-coded flag specifying dialog display settings
;; Returns: [str] Selected folder filepath, else nil.
(defun LM:browseforfolder ( msg dir bit / err fld pth shl slf )
(setq err
(vl-catch-all-apply
(function
(lambda ( / app hwd )
(if (setq app (vlax-get-acad-object)
shl (vla-getinterfaceobject app "shell.application")
hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir)
)
(setq slf (vlax-get-property fld 'self)
pth (vlax-get-property slf 'path)
pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
)
)
)
)
)
)
(if slf (vlax-release-object slf))
(if fld (vlax-release-object fld))
(if shl (vlax-release-object shl))
(if (vl-catch-all-error-p err)
(prompt (vl-catch-all-error-message err))
pth
)
)
(princ)
Tips for running the function:
1. Save the Batcher_XRef.lsp file to a support directory.
2. Copy all target drawings to a temp directory.
3. Start a new drawing.
4. Drag/drop Batcher_XRef.lsp onto the new drawing.
5. Type: Batcher_XRef at the command line.
6. Select the temp directory where the files reside.
7. Grab a cup of coffee.
8. Move/overwrite the drawings back into the directory they were copied from after the function has completed.
The XRef portion of the code is untested, but should suffice.
AutoCad 2018 (full)
Win 11 Pro