Author Topic: Search path...  (Read 12565 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 462
Search path...
« on: July 23, 2013, 01:20:37 AM »
I know that a specified file is existing and I want to find its location.
How do I get the path of the document (txt, doc... etc.)?
Thanks in advance.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Search path...
« Reply #1 on: July 23, 2013, 02:33:48 AM »
I've used this successfully for a while ..

Code - Auto/Visual Lisp: [Select]
  1. ;;(findFileFromRoot "D:\\"  "FileName.ext")
  2. ;;(findFileFromRoot "D:\\folder\\"  "FileName.ext")
  3. (defun findFileFromRoot (root file)
  4.   (setq root (vl-string-right-trim "\\"
  5.                                    (vl-string-translate "/" "\\" root)
  6.              )
  7.   )
  8.   (cond ((findfile (strcat root "\\" file)))
  9.         ((vl-some '(lambda (fn)
  10.                      (if (wcmatch fn "`.,`.`.")
  11.                        nil
  12.                        (findfilefromroot (strcat root "\\" fn) file)
  13.                      )
  14.                    )
  15.                   (vl-directory-files root nil -1)
  16.          )
  17.         )
  18.   )
  19. )

Code - Auto/Visual Lisp: [Select]
  1. (findFileFromRoot "K:\\SteelTools\\"  "KDUB_3DPlate.lsp")

Quote from:  RETURNS
"K:\\SteelTools\\SOURCE_19\\MISC TOOLS\\KDUB_3DPlate.lsp"
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Search path...
« Reply #2 on: July 23, 2013, 03:00:02 AM »
I've used this successfully for a while ..

Code - Auto/Visual Lisp: [Select]
  1. ;;(findFileFromRoot "D:\\"  "FileName.ext")
  2. ;;(findFileFromRoot "D:\\folder\\"  "FileName.ext")
  3. (defun findFileFromRoot (root file)
  4.   (setq root (vl-string-right-trim "\\"
  5.                                    (vl-string-translate "/" "\\" root)
  6.              )
  7.   )
  8.   (cond ((findfile (strcat root "\\" file)))
  9.         ((vl-some '(lambda (fn)
  10.                      (if (wcmatch fn "`.,`.`.")
  11.                        nil
  12.                        (findfilefromroot (strcat root "\\" fn) file)
  13.                      )
  14.                    )
  15.                   (vl-directory-files root nil -1)
  16.          )
  17.         )
  18.   )
  19. )

Code - Auto/Visual Lisp: [Select]
  1. (findFileFromRoot "K:\\SteelTools\\"  "KDUB_3DPlate.lsp")

Quote from:  RETURNS
"K:\\SteelTools\\SOURCE_19\\MISC TOOLS\\KDUB_3DPlate.lsp"
Thanks so much, Kerry.
I will try it out tomorrow.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Search path...
« Reply #3 on: July 23, 2013, 03:39:34 AM »
Just be warned that searching through lots of sub-folders could take some time. Even worse if searching on a network / remote folder. Here's a thread which does some testing of various searching methods:
http://forums.augi.com/showthread.php?132773-Search-file-in-a-specific-drive&p=1141241&viewfull=1#post1141241
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Search path...
« Reply #4 on: July 23, 2013, 08:23:52 AM »
I've used this successfully for a while ..

Code - Auto/Visual Lisp: [Select]
  1. ;;(findFileFromRoot "D:\\"  "FileName.ext")
  2. ;;(findFileFromRoot "D:\\folder\\"  "FileName.ext")
  3. (defun findFileFromRoot (root file)
  4.   (setq root (vl-string-right-trim "\\"
  5.                                    (vl-string-translate "/" "\\" root)
  6.              )
  7.   )
  8.   (cond ((findfile (strcat root "\\" file)))
  9.         ((vl-some '(lambda (fn)
  10.                      (if (wcmatch fn "`.,`.`.")
  11.                        nil
  12.                        (findfilefromroot (strcat root "\\" fn) file)
  13.                      )
  14.                    )
  15.                   (vl-directory-files root nil -1)
  16.          )
  17.         )
  18.   )
  19. )

Looks familiar...  :roll: :(

« Last Edit: July 23, 2013, 08:35:11 AM by Lee Mac »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Search path...
« Reply #5 on: July 23, 2013, 08:36:50 AM »
< .. >

Looks familiar...  :roll: :-(

Lee, I've been writing code from the time you were in nappies.
There are a couple of pieces of code in the world that you didn't write (or re-write) you know, so don't roll your bloody eyes at me.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Search path...
« Reply #6 on: July 23, 2013, 09:34:02 AM »
< .. >

Looks familiar...  :roll: :-(

Lee, I've been writing code from the time you were in nappies.
There are a couple of pieces of code in the world that you didn't write (or re-write) you know, so don't roll your bloody eyes at me.

I couldn't care less how long you've been writing code for - that's no excuse for plagiarism.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Search path...
« Reply #7 on: July 23, 2013, 09:37:43 AM »
I loath taking sides, I like both you gentlemen, but I do not believe for a nano second that Kerry has plagiarized anyone's code and an apology is due.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Search path...
« Reply #8 on: July 23, 2013, 10:06:04 AM »
You expect me to believe that carbon copy of my code was written independently?

owenwengerd

  • Bull Frog
  • Posts: 451
Re: Search path...
« Reply #9 on: July 23, 2013, 10:51:21 AM »
It's possible for anybody to unwittingly copy code they saw previously without even realizing it. Sometimes it's impossible to determine which is the original and which is the copy. Plagiarism should be called out when it's found, but Lee I think you should explain the discrepancy between the code on your web site and the (apparently more recent) code in your post before leveling plagiarism charges.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Search path...
« Reply #10 on: July 23, 2013, 10:55:35 AM »
Be careful Lee -- it's a double edged sword you're wielding -- Kerry is a well respected author, one who has advocated, and demonstrated proper attribution for decades -- how do we know you didn't "roll yer own" based upon his original work and then forgot where you got the inspiration?

As stated, I like you both, respect both of your collective works and significant contribution to the knowledge pool, but unless you can prove the plagiarism assertion it remains a really unfortunate gaffe.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Search path...
« Reply #11 on: July 23, 2013, 11:09:27 AM »
I think you should explain the discrepancy between the code on your web site and the (apparently more recent) code in your post before leveling plagiarism charges.

I simply updated the code as published on my site when posting in the thread to which I have referred - you will see the distinct similarities between the code as found on my site and the updated version.

how do we know you didn't "roll yer own" based upon his original work and then forgot where you got the inspiration?

Since Kerry's post above of the 'findfilefromroot' function appears to be the only occurrence of the function not only here at the Swamp, but across the entire web, I think its evident who has copied from who.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Search path...
« Reply #12 on: July 23, 2013, 11:17:06 AM »
Sorry, not evident to me. This is an ugly thread. I'm out.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

owenwengerd

  • Bull Frog
  • Posts: 451
Re: Search path...
« Reply #13 on: July 23, 2013, 11:33:10 AM »
I simply updated the code as published on my site when posting in the thread to which I have referred...

One might infer that you updated your code after seeing Kerry's more efficient version.

For such a simple function, identical variable names and code are not sufficient in and of themselves to prove infringement. It comes down not to similarity, but who created it first, and did the second person have access to the first or did both arrive at the same implementation independently. You published in February and you can prove it. I expect Kerry to either provide evidence that his came earlier, or concede that he copied your code.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Search path...
« Reply #14 on: July 23, 2013, 01:05:35 PM »
One might infer that you updated your code after seeing Kerry's more efficient version.

I fully appreciate that point, however as I've noted, this is the first appearance of Kerry's function not only on this forum, but on the entire web as far as I can tell, and so I can assure you that this is the first I have seen of it.

CADDOG

  • Newt
  • Posts: 82
  • wishbonesr
Re: Search path...
« Reply #15 on: July 23, 2013, 02:03:38 PM »
I'm such a noob here, and will probably shoot myself in the foot as good judgement tells me to bite my tongue...

Publishing is king, as owen has stated.  And that applies to algorithms as much as code.
For instance, I believe I was the first to publish an Autolisp MergeSort stable algorithm, however I can only claim the implementation based on Ellis Dee's vb implementation

If either one of you guys were to walk away from this site would be tragic.  Come on.  This isn't adndevblog  :angel:

But here's some food for thought.
I've done it before (arrived to code that was near identical to someone else’s) with no intention whatsoever.  However, what influenced the design was that of previous optimization efforts I observed;  Because.....

This site has really transformed v-lisp knowledge and optimization is a constant competition.  Ultimately this site has exposed best practices, even though there might be multiple directions; So it's not too far of a stretch that similar, sometimes identical, methods are derived with no intention of copying.

Here's a example of what might happen among friends, focusing on alanjt, and alan - and then subsequently alan the t.willey.  This is also and example of how these functions, in my opinion, have contributed to many other optimized functions.
Or over here recently

In my opinion Kerry over-reacted.  It's not uncalled for Lee's notice of pre-existing posts, however I would have just posted the link.  He made no direct accusations as MP suggested (at first), rather opened the dialog for the research and due credit (if due) is given.  It was implied only; And how else would a discussion of credit be brought about?  More tact? Maybe.

Both gentlemen have exhibited integrity here and elsewhere.  As a nobody, but only in finding your contributions to many of my questions and others here, you all show friendship to others and myself.  I know that I overstep, but what little friendship I have, I ask  that your first see the perspective of the other, and when done, you most certainly will know that you must shake hands on this one.

Most Sincerely,
Ricky
« Last Edit: July 23, 2013, 02:36:24 PM by CADDOG »

LE3

  • Guest
Re: Search path...
« Reply #16 on: July 23, 2013, 04:07:47 PM »
I know that a specified file is existing and I want to find its location.
How do I get the path of the document (txt, doc... etc.)?
Thanks in advance.

I wrote this many moons ago, see if works:
Code: [Select]
(defun search_sub_folders  (pathfile ext)
  (mapcar '(lambda (sub)
     (cons sub
   (vl-directory-files
     (strcat pathfile sub)
     ext
     1)))
  (vl-directory-files
    (vl-filename-directory
      pathfile)
    nil
    -1)))

This one I just put it together:
Code: [Select]
(defun findFileOnFolders  (path name extension)
  (vl-some '(lambda (f)
      (findfile (strcat path (car f) "\\" name extension)))
   (search_sub_folders path (strcat "*" extension))))

usage:
Quote
(FINDFILEONFOLDERS "C:\\" "attleft" ".lsp")
"C:\\My_Stuff\\attleft.lsp"

HTH.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Search path...
« Reply #17 on: July 24, 2013, 07:53:58 AM »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Search path...
« Reply #18 on: July 24, 2013, 09:20:32 AM »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: Search path...
« Reply #19 on: July 24, 2013, 11:00:41 AM »
Lee, you take your "online image" far too seriously. ...this is the internet, not real life. A series of 1s and 0s is isn't tangible. Go outside and give a perfect stranger a reason to laugh.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

andrew_nao

  • Guest
Re: Search path...
« Reply #20 on: July 24, 2013, 11:16:29 AM »
Just be warned that searching through lots of sub-folders could take some time. Even worse if searching on a network / remote folder....

i tried it on a network with 1000 directories, and it locked up my acad.
im sure there is a limit on how many directories can search without causing issues.

would anyone have a good guess as to how many?

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Search path...
« Reply #21 on: July 24, 2013, 11:23:25 AM »
Lee, you take your "online image" far too seriously. ...this is the internet, not real life. A series of 1s and 0s is isn't tangible. Go outside and give a perfect stranger a reason to laugh.
I'm going to disagree.
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: Search path...
« Reply #22 on: July 24, 2013, 11:25:51 AM »
I'm going to disagree.

With what?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Search path...
« Reply #23 on: July 24, 2013, 11:29:31 AM »
Lee, you take your "online image" far too seriously. ...this is the internet, not real life. A series of 1s and 0s is isn't tangible. Go outside and give a perfect stranger a reason to laugh.

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Search path...
« Reply #24 on: July 24, 2013, 11:31:21 AM »
All my better judgement says to stay out of this but anyhoo FWIW..

Let me preface this with I highly respect both of these members.

I don't think this is about Lee's online image. He's mad because he thinks that someone copied his code, changed a couple of lines and took credit (whether that's the case ... ) You can spin it 10 different ways but if in fact this is true it's wrong.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Search path...
« Reply #25 on: July 24, 2013, 11:32:48 AM »
I'm going to disagree.

With what?
Sorry. His online image. In this day and age your online image is fast becoming who you are.
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: Search path...
« Reply #26 on: July 24, 2013, 11:34:09 AM »


Sorry, I am still behind the company firewall; I cant see the image.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Search path...
« Reply #27 on: July 24, 2013, 11:35:00 AM »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: Search path...
« Reply #28 on: July 24, 2013, 11:41:28 AM »
Sorry. His online image. In this day and age your online image is fast becoming who you are.
Sadly, I kind of agree but if I can get a little sappy, cliche, stupid, etc. for a moment: I've come to realize there are far more important things in life. ...I was just trying to make the observation that it may be time for him to "disconnect" a bit. Just, tossing it out there.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: Search path...
« Reply #29 on: July 24, 2013, 11:43:35 AM »
Apology accepted.

Glad that's settled. Wanna go get some coffee?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Search path...
« Reply #30 on: July 24, 2013, 11:45:22 AM »
Glad that's settled. Wanna go get some coffee?

beer sounds more better
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: Search path...
« Reply #31 on: July 24, 2013, 11:48:12 AM »
beer sounds more better

I'm on the clock but what-the-hell, I have some vacation hours left. You buy the first round and I'll be there in a few.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Search path...
« Reply #32 on: July 24, 2013, 11:49:53 AM »
You buy the first round and I'll be there in a few.

Right. Drinking by myself again, fml.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: Search path...
« Reply #33 on: July 24, 2013, 12:05:21 PM »
Right. Drinking by myself again, fml.
Nope. You're my boy Blue! A small warning though, if you're gonna roll with me you have to bring an emergency kit: [ e.g. passport, tire repair kit, pitching wedge, and a spare set of socks ]. Last time me and the friends ended up in Northern MN in a lakeside motel. The owners comp'd us to two free rooms so, all-in-all it turned out to be a pretty cool night.  ...let's go.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Search path...
« Reply #34 on: July 24, 2013, 12:27:41 PM »
Nope. You're my boy Blue!

Weird. Ok, So I've never seen the movie "Old School", and accordingly, the "boy blue" phrase is new to me. Ok, the weird part. It's mostly new to me. My boss said it to me a couple times over the last month or so and I was like "whaaaa???". Now you've gone and used it. <blink> Guess I'll have to see the movie to appreciate what it means. Cannae do youtube from here and quick internet searches don't give me a good sense of what it means. tl;dr: I'm ignorant, this is not news and apologies for running this thread completely off the rails.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: Search path...
« Reply #35 on: July 24, 2013, 12:43:44 PM »
Weird. Ok, So I've never seen the movie "Old School"...

lol No, that's cool! Just a term of endearment/rally cry. It's one of those movies you only need to see once (funny the first time and after the fact).

I had the same scenario with Jenny and the "Holly Grail". I had Jen watch it and the whole time she was complaining it was a stupid movie. But afterwards when she was in the shower and I ran in the bathroom and said: "run away! run far away!". I thought she was going to slip and fall down because she was laughing so hard.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Search path...
« Reply #36 on: July 24, 2013, 02:07:41 PM »
Just be warned that searching through lots of sub-folders could take some time. Even worse if searching on a network / remote folder....

i tried it on a network with 1000 directories, and it locked up my acad.
im sure there is a limit on how many directories can search without causing issues.

would anyone have a good guess as to how many?

If you have to search through more than a handful of folders to find a support file, its time to re-evaluate the current scheme.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Search path...
« Reply #37 on: July 24, 2013, 02:53:22 PM »
lol No, that's cool! Just a term of endearment/rally cry ...

Ahhh cool; thx. In the interests of curbing any further thread de-railing capping it at that; cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

andrew_nao

  • Guest
Re: Search path...
« Reply #38 on: July 24, 2013, 03:18:54 PM »
Just be warned that searching through lots of sub-folders could take some time. Even worse if searching on a network / remote folder....

i tried it on a network with 1000 directories, and it locked up my acad.
im sure there is a limit on how many directories can search without causing issues.

would anyone have a good guess as to how many?

If you have to search through more than a handful of folders to find a support file, its time to re-evaluate the current scheme.

i just testing with 1000 to see how deep i could take it and how long it would go.
i personally would just find the path of the file and hardcode it in

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Search path...
« Reply #39 on: July 24, 2013, 05:42:00 PM »
Hardcoding paths require changes to code if the path changes.  Look at the number of posters who have a LISP they inherited and need to make it work on a new computer, new network location, new AutoCAD version.  To my mind changing data requires less knowledge than changing code, so I use a combination of registry values, XML files, and generic search patterns to handle changes with less work and by those who don't understand LISP (like IT  :angel: ).
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Search path...
« Reply #40 on: July 25, 2013, 01:10:40 AM »
i tried it on a network with 1000 directories, and it locked up my acad.
im sure there is a limit on how many directories can search without causing issues.
would anyone have a good guess as to how many?
Nope, it's a bit like asking: "How long is a string?"

It all depends on how fast your whole setup is. I.e. discs, network connection, PC, OS's filesystem interface (both yours and the server's), congestion on the network, number of files in each folder, number of folders, length of filenames, etc. etc. etc.

That's why I posted the link to that other thread. The only way to limit the amount the function needs to search through would be to use something like dgorsman's idea of depth-limiting. I.e. how deep you search into nested folders. Or use a list of possible folders through which to search - i.e. add the folder into your Support Folders Search Path and use the findfile function.

Hardcoding paths require changes to code if the path changes.  Look at the number of posters who have a LISP they inherited and need to make it work on a new computer, new network location, new AutoCAD version.  To my mind changing data requires less knowledge than changing code, so I use a combination of registry values, XML files, and generic search patterns to handle changes with less work and by those who don't understand LISP (like IT  :angel: ).
Too true, if you constantly need to search for a file you need to find another way. Either add it to your SFSP, or have a setting which tells you where it is (Registry or some file in acad's setup folders). That's going to be exponentially faster than even limiting the depth of nested search folders.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Search path...
« Reply #41 on: July 25, 2013, 02:19:18 AM »
I know that a specified file is existing and I want to find its location.
How do I get the path of the document (txt, doc... etc.)?
Thanks in advance.
This might be a bit late in this thread  :? Hidden in the other matter  :-(

But re-reading the OP, I'd like to ask a question: When you state that you know the specified file exists, do you already have it somewhere (say in a variable) and simply want to know its path? E.g. is it in the same folder as your DWG? Or perhaps even in the same folder as your CUI(x) file?
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

andrew_nao

  • Guest
Re: Search path...
« Reply #42 on: July 25, 2013, 01:10:09 PM »
Hardcoding paths require changes to code if the path changes.  Look at the number of posters who have a LISP they inherited and need to make it work on a new computer, new network location, new AutoCAD version.  To my mind changing data requires less knowledge than changing code, so I use a combination of registry values, XML files, and generic search patterns to handle changes with less work and by those who don't understand LISP (like IT  :angel: ).

if youre starting from scratch, to me anyway, it would make sense to hardcode the path.

however, im the type of person that would take the time to try and modify the code

andrew_nao

  • Guest
Re: Search path...
« Reply #43 on: July 25, 2013, 01:12:25 PM »
.. i.e. add the folder into your Support Folders Search Path and use the findfile function.
that sounds like it would be the best idea, use code to add the paths to the SFSP


MeasureUp

  • Bull Frog
  • Posts: 462
Re: Search path...
« Reply #44 on: July 25, 2013, 11:42:35 PM »
To Kerry:
your code works but it is slow when searching in entire disk or in network server, as irneb points out. Thanks.

To Kerry and Lee:
Both of you have helped me a lot in the past. I appreciate your help very much.
I think what CADDOG said is right. Hope you can give more explanation to each other without fighting in any kind. I am a bit upset when you are angry as both of you are vary good in programming and have helped many people here.
« Last Edit: July 26, 2013, 12:11:19 AM by MeasureUp »

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Search path...
« Reply #45 on: July 26, 2013, 12:03:52 AM »
To irneb and andrew_nao:
It is nothing about SFSP in this case because the target file may not be a drawing file in most of time (i.e. it may be a project note, a photo, xls and they may not be in the project drawing folder).
I am thinking that if I can grab the path of the document then I may add a file to the same directory.
As I found out the search time by using the code is amost the same when searching in the windows explorer.
Thanks for your time and help.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Search path...
« Reply #46 on: July 26, 2013, 01:30:40 AM »
To irneb and andrew_nao:
It is nothing about SFSP in this case because the target file may not be a drawing file in most of time (i.e. it may be a project note, a photo, xls and they may not be in the project drawing folder).
I am thinking that if I can grab the path of the document then I may add a file to the same directory.
You know that the SFSP is used to find "any" file ... not just DWG files. And if it is project specific, you might also want to try using the PFSP (Project Folder Support Path) in which case it is specific to a project. What I'm trying to explain, is that you should really try to use any other possibility to get to that particular file's path. This brute-force searching should only be used as a very last resort, i.e. there is absolutely NO other way anyone can think of. In order to tell if this is the case we need a lot more info about how those files are stored, whether there is any place which is easily findable which points to those files.

As I found out the search time by using the code is amost the same when searching in the windows explorer.
In general yes, though this method of searching doesn't use the Windows Search Index optimizations. So potentially it can be slower than the Explorer based search. As I hinted, it's a brute force method - and those tend to be the worst case performance wise.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Search path...
« Reply #47 on: July 26, 2013, 02:36:32 AM »
To Kerry:
your code works but it is slow when searching in entire disk or in network server, as irneb points out. Thanks.

<..>

Yes, I know it's slow ... that is to be expected considering the amount of work the recursion is doing.
One version I had returned a list of matches and presented them in a dialog for selection.

//--------------

Regarding the other matter : I'm not angry, just dissapointed.

I attribute code where I can.  In this case attribution is not necessary.
I have thousands of lines of code here and I don't intend 'publishing' it just to proove a point.
I have no control over what others think and frankly I don't care too much. I don't need to be validated : I have my integrity and I sleep at night.

I'm sorry that your thread copped a thrashing :)

Regards.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

andrew_nao

  • Guest
Re: Search path...
« Reply #48 on: July 26, 2013, 08:53:59 AM »
To irneb and andrew_nao:
It is nothing about SFSP in this case because the target file may not be a drawing file in most of time (i.e. it may be a project note, a photo, xls and they may not be in the project drawing folder).
I am thinking that if I can grab the path of the document then I may add a file to the same directory.
You know that the SFSP is used to find "any" file ... not just DWG files. And if it is project specific, you might also want to try using the PFSP (Project Folder Support Path) in which case it is specific to a project. What I'm trying to explain, is that you should really try to use any other possibility to get to that particular file's path. This brute-force searching should only be used as a very last resort, i.e. there is absolutely NO other way anyone can think of. In order to tell if this is the case we need a lot more info about how those files are stored, whether there is any place which is easily findable which points to those files.

As I found out the search time by using the code is amost the same when searching in the windows explorer.
In general yes, though this method of searching doesn't use the Windows Search Index optimizations. So potentially it can be slower than the Explorer based search. As I hinted, it's a brute force method - and those tend to be the worst case performance wise.

one piece of programing i have, well this function was made by Lee, so i cant take to much credit for but this function i use to find the file in a directory that is not in my SFSP

Code: [Select]

(setq joborder "12345")

;; Lee Mac code
(defun wcmatch_first ( dlst pattern flag / result )
    (setq pattern (if flag (strcase pattern) pattern))
    (vl-some
       '(lambda (str) (if (wcmatch str pattern) (setq result str)))
        (if flag (mapcar 'strcase dlst) dlst)
    )
    result
)

;; -- find summary file based on order number
(SETQ dlst (VL-DIRECTORY-FILES "O:\\" nil -1))
(if (setq dir (strcat "O:\\" (wcmatch_first dlst (strcat "*" joborder "*") nil)))
(progn
   (SETQ dLST (VL-DIRECTORY-FILES DIR "*.DOC"))
   (if (setq ndir (wcmatch_first dlst (strcat "*" "Follow-Up" "*") nil))
  (setq path (findfile (strcat dir "/" ndir)))
              (alert "File Has not been created yet") ; not found    
            ) ;if
) ;progn
        (alert "No such Order exists") ; not found
) ;if
what this does its looks in my O:\ drive (a network drive) for this directory, then once it finds this directory it looks inside for the follow-up file.
as you can see, i have the network drive hardcoded in and thats because the file im looking for with this code will ALWAYS be in that drive and no other drive.
the file name changes slightly however "follow-up" will always be in the file name

maybe this could help