How do I search for a file?

This is a discussion on How do I search for a file? within the C++ Programming forums, part of the General Programming Boards category; Yepp, like the thread says. How to I search for a file on the system with my program? Like if ...

  1. #1
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90

    How do I search for a file?

    Yepp, like the thread says.
    How to I search for a file on the system with my program?

    Like if I need to open settings.txt but are not sure where it is.
    (OUTSIDE the folder where the program is)

    And save the the file location to a string.
    So I can use it later.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Well, a simple but perhaps a bit contrived answer would be to concatinate the file name with various pathnames and try to open each of them. If the file opens, then you have a match.
    Sent from my iPadŽ

  3. #3
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    Hmm thats just stupid.
    Aint there any way to search for files?

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Well, really, how do you think Windows does it when you use their search function? It's called brute-forcing.
    Sent from my iPadŽ

  5. #5
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    If you're using windows check out this site:-

    http://www.adrianxw.dk/SoftwareSite/...irstFile1.html


    But if you don't know where your file might be and you have to recursively search your c: drive be prepared for a long wait?


  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    Yes, that type of brute-forcing would not be a good idea, and it is not how an OS searches for files.

    Depending on your OS, there are file finding methods available to do the searching for you. Check the FAQ, I believe it has some options, or search the board.

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Quote Originally Posted by Daved
    Yes, that type of brute-forcing would not be a good idea
    As long as your careful with how you open the files, I don't see what harm you could do.
    Sent from my iPadŽ

  8. #8
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    ...it also depends on how deep you want to get into searching... for example, is your program just a dedicated searching tool (like how google started)? then it'll be worth it to look into some hardcore searching algorithms, but if if it's just doing a quick search, don't worry too much about it.

    if you're going the route of brute-forcing, I'd check each directory recursively. I don't know why you'd need to check an entire system for a file though, seeing as if you know it should/could be there, you probably know some of the most common places it'd be.

    I'd ask if they have the file, if they say 'yes' or 'idk', then tell them you're going to try to find it. search common places, and if it's not there, ask them if they know where it is. if they say 'yes' and give you a valid location, yay. if they say 'yes' and give you an invalid location, tell them and give them the option to try again or create the file. if they don't know if they have it or know they don't, just create it.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 05:14 AM
  2. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21