I'm trying to get the file name of a file outside the search path. Obviously (findfile) is not an option. The file location changes with each project so adding a search path is also not an option. I can get the path to the file but i can't seem to figure out how to get the file name. I can also get the first set of characters, as they are constant from project to project, it's just the end of the file name that changes. The file is always a PDF.
Any help would be greatly appreciated.
I hope this provides enough information.
Thanks in advance,
Larry
Solved! Go to Solution.
Solved by BlackBox_. Go to Solution.
@bdsmls wrote:... I can get the path to the file but i can't seem to figure out how to get the file name. I can also get the first set of characters, as they are constant from project to project, it's just the end of the file name that changes. The file is always a PDF.
How are you getting the path the the file?
Is the target file obtained relative to the project, or drilled down from a specific drive?
What are those consistent, first set of characters?
More information is needed.
Cheers
"How we think determines what we do, and what we do determines what we get."
the file name is "(project number) shop standards (varies).pdf"
an example would be:
13-327 shop standards net.pdf
How about calling (vl-directory-files ...)?
Here's a quick sub-function, which returns a list of matching file names (as string):
(vl-load-com) (defun _GetProjectFile (pattern / files) ;; Example: ;; (_GetProjectFile "13-327*.pdf") (vl-directory-files (strcat (getvar 'dwgprefix) "Shop Standards\\") pattern 1 ) )
HTH
"How we think determines what we do, and what we do determines what we get."
i tried (vl-directory-files ...) but i wasn't able to use a variable for the file location to search, it would only work if i spelled out the location. since the location changes that wasn't working for me.
@bdsmls wrote:i tried (vl-directory-files ...) but i wasn't able to use a variable for the file location to search, it would only work if i spelled out the location. since the location changes that wasn't working for me.
If the location of the PDF, relative to the ActiveDocument is (strcat (getvar 'dwgprefix) "Shop Standards\\"), and the file name always starts with the project number, as you've stated above... Then vl-Directory-Files should work just fine... You'd need only implement a means by which to extract the project number prior to supplying as a parameter to the sub-function I posted here.
"How we think determines what we do, and what we do determines what we get."
(setq tpath "c:\\some path here") (setq tlist (vl-directory-files tpath "*.pdf" 1 ) )
Feed in a single location, or loop against a list of locations, or...
@dgorsman wrote:(setq tpath "c:\\some path here") (setq tlist (vl-directory-files tpath "*.pdf" 1 ) )
Feed in a single location, or loop against a list of locations, or...
Given that the relative project folder is consistent according to the OP here, I'm not sure I follow how your offering is more efficient than this offering... In lieu of supplying a location as an argument, the OP should instead supply a project number specific pattern, no?
Cheers
"How we think determines what we do, and what we do determines what we get."
@bdsmls wrote:
The problem with this solution is the file path changes with every project. If the path was constent it would have been easy.
I did find an error in my routine which i fixed, but now when i get the file name via (vl-directory-files ...) the file name is in parenthesis which causes a problem when I try to call it. I wasn't able to remove the parenthesis with SUBSTR. So what is my solution for removing the parenthesis from the file name?
The returned value is a list of strings....
(car (vl-directory-files <file path> <pattern> 1))
"How we think determines what we do, and what we do determines what we get."
Naturally, you would set the search path to start with using whatever means are available. That would include setting up and iterating a list of possible folders, if required. Just a very simple kick-in-the-seat example.
Oh, and check the LISP help - it will indicate the return type for the various LISP functions (in this case, a list or nil).
Thanks Blackbox for pointing out it was a list and providing a solution. I now have the routine working perfectly.
Thank you also dgorsman for your input. It is greatly appreciated.
Larry
@bdsmls wrote:Thanks Blackbox for pointing out it was a list and providing a solution. I now have the routine working perfectly.
You're welcome, bdsmls; I'm happy to help.
Don't forget to mark the appropriate post as solution.
Cheers
"How we think determines what we do, and what we do determines what we get."