0

I'm doing a program and one of its uses is to import data via file. My problem is the following:

  • The user is "dumb", therefore i only want him to introduce the name of the file he wants to import.

  • How can I using only the name find the file? Is there any function that does the reverse of PathFindFileName()? Instead of giving me the name of the file using the path, it gives me path introducing the name?

If you have a simpler answer or solution then this, any help will be useful.

PS: the user can only use the console to introduce or see Data, no GUI.

InsaniTea
  • 11
  • 4
  • 3
    How would you differentiate between files of the same name in different locations? What platform because it is handled differently per operating system. – George Houpis Dec 15 '14 at 19:02
  • That's one of my problems. I know that if the user used a file with a generic name (File.txt for example), the odds of being the file he wanted are slim. that why I'm accepting any other suggestions of getting the file he wants. But the user can only use console to insert or see data – InsaniTea Dec 15 '14 at 19:13
  • Show them a list and let them choose. No GUI needed for that. The OS cannot easily find a file given just a name. If you want to enumerate all files in all directories on all network shares in order to find a file, feel free to do so, but bear in mind that it will take an unknown amount of time, possibly hours. – n. m. could be an AI Dec 15 '14 at 19:28
  • Can you restrict the user to only saving and reading from a specific directory? If not, I think the best solution is to not assume your users are dumb. – Matt Coubrough Dec 15 '14 at 20:59
  • I cannot do that restriction, in the projects description it says that "The file reading mechanism must be user-friendly and efficient, not limited to default locations." – InsaniTea Dec 15 '14 at 21:39

1 Answers1

1

There are actually facilities in Windows to find files based on filename, and to do so quickly if indexing is enabled--don't listen to the negative comments above. However, it's a lot of work, far more than calling "PathFindFileName"; I honestly think it will be overkill unless this is a serious/hard requirement.

Windows Search docs: http://msdn.microsoft.com/en-us/library/windows/desktop/aa965362%28v=vs.85%29.aspx

SDK download: http://www.microsoft.com/en-us/download/details.aspx?id=7388

StilesCrisis
  • 15,972
  • 4
  • 39
  • 62
  • thank you for the useful info and the positive comment :) I am going to talk with my teacher to see if it is mandatory to just ask the name. If it is your comment was very useful. If it isn't I'll simply ask the user for the path of the file. Its a simpler solution if they let me "cheat" the rules a bit – InsaniTea Dec 15 '14 at 20:48
  • If this is for a class, I can't imagine you would need to learn the entire search SDK for one assignment. It's not something I would expect a student to be able to pick up without existing COM experience. – StilesCrisis Dec 16 '14 at 01:04
  • it's not a simple assignment, it's a project that my teacher gave us that we have to develop from the ground up, and if i can present some knowledge other than the ones the demand, it would be great. that why i didn't want to take the "easy route" by asking the user for the path to the file, and wanted to find some other way that would make the "user"'s life easier, and would teach me something. but thanks for the feedback :) – InsaniTea Dec 16 '14 at 10:43
  • BTW, there are other simpler APIs you can use; they are much slower but you are more likely to be able to implement them in a short amount of time. See http://stackoverflow.com/questions/67273/how-do-you-iterate-through-every-file-directory-recursively-in-standard-c for a list. – StilesCrisis Dec 16 '14 at 15:18
  • since time is not one of the problems (not file wise at least) I'm going to search the list you gave-me, thank you. I prefer something i can understand and explain, so the list you gave me is very useful. – InsaniTea Dec 16 '14 at 19:54