Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get filename from outside the search path

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
bdsmls
527 Views, 15 Replies

Get filename from outside the search path

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

15 REPLIES 15
Message 2 of 16
BlackBox_
in reply to: bdsmls


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

Message 3 of 16
bdsmls
in reply to: bdsmls

(SETQ DWGDIR(GETVAR "DWGPREFIX"))
(SETQ PDFDIR(STRCAT DWGDIR"Shop Standards\\"))

Message 4 of 16
bdsmls
in reply to: BlackBox_

the file name is "(project number) shop standards (varies).pdf"

an example would be:

13-327 shop standards net.pdf

Message 5 of 16
dgorsman
in reply to: bdsmls

How about calling (vl-directory-files ...)?

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 6 of 16
BlackBox_
in reply to: bdsmls

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

Message 7 of 16
BlackBox_
in reply to: dgorsman


@dgorsman wrote:

How about calling (vl-directory-files ...)?


You beat me to it... *kicks dirt*

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 8 of 16
bdsmls
in reply to: dgorsman

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.

Message 9 of 16
BlackBox_
in reply to: bdsmls


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

Message 10 of 16
dgorsman
in reply to: bdsmls

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

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 11 of 16
BlackBox_
in reply to: dgorsman


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

Message 12 of 16
bdsmls
in reply to: dgorsman

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?
Message 13 of 16
BlackBox_
in reply to: bdsmls


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

Message 14 of 16
dgorsman
in reply to: bdsmls

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

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 15 of 16
bdsmls
in reply to: BlackBox_

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

Message 16 of 16
BlackBox_
in reply to: bdsmls


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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost