Finding your Start In Folder using Lisp

Posted by Jason Bourhill on 6 March 2012 | 0 Comments

Tags: , , , , ,

Sometimes you may need to know what folder AutoCAD/Bricscad is running out of. This may not necessarily be the same folder as any drawings you have currently open. It is dependant on the "start-in" folder specified in the shortcut that you have used to launch the application.


A simple solution to find your "start in" folder is to make use of the lisp function findfile. Normally you would use this function to confirm whether a specified file exists, but you can also use it to retrieve a folder name by using the following format:

(findfile ".")

assuming our current folder is "C:\Users\jason\Documents" This will return:

AutoCAD "C:\\Users\\jason\\Documents"
Bricscad "C:\\Users\\jason\\Documents\\."

To get Bricscad to return just the folder (without the "." on the end ) you need to use:

(findfile ".\\")

Paradoxically this doesn't work in AutoCAD, instead it returns nil. For this particular function it would appear that Briscad is more flexible, working for all manner of relative folder references. The table below gives a summary of some common ones you might want to use:

AutoCAD Bricscad Result
(findfile ".") (findfile ".\\") "C:\\Users\\jason\\Documents\\"
(findfile "..") (findfile "..\\") "C:\\Users\\jason\\"
(findfile "..\\..\\") (findfile "..\\..\\") "C:\\Users\\"
(findfile "\\.") (findfile "\\") "C:\\"
(findfile "..\\Other\\") (findfile "..\\Other\\") "C:\\Users\\jason\\Other\\"

Why does this work? Well . and .. are special folder names referring respectivelty to the current folder and parent folder names. These special folders are present in every folder you create in Windows. What's better is that the same system is used in Linux, which means this method will work without alteration in both environments.