| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
How can i search for a file in windows? i looked, and looked for a method but with no luck.
I only found this but it is .NET and i dont know anything about that: //declare a delegate function private delegate void FindAsyn(); [STAThread] static void Main(string[] args) { FileFind ff = new FileFind(); //subscribe the found file event ff.OnFileFound += new FoundDelegate(OnFoundFile); //The directory to be searched ff.PathName = @"C:\MyFileDir"; //The text to be searched ff.FindText ="findtext"; //delegate to... FindAsyn f = new FindAsyn(ff.StartSearch); //invoke the searching function asynchronously f.BeginInvoke(null,null); Console.Read(); // pause the screen; FileFind.bStopIt = true; // stop it if the process takes // too long. Console.Read(); //unsubscribe the event ff.OnFileFound -= new FoundDelegate(OnFoundFile); } private static void OnFoundFile(string filename) { Console.WriteLine(filename); } Do you know a function or a lib with a search function or do you know i i can implement this .NET code? |
|
#2
|
||||
|
||||
|
For native c++ you can use FindNextFile http://msdn2.microsoft.com/en-us/library/aa364428.aspx
alternatively you could use boost::filesystem which is portable http://boost.org/libs/filesystem/doc/index.htm You can generally not 'implement' .NET code in native c++ since .NET is not a native platform. So the functions you have in .NET (for instance c#) are supplied by the .NET framework on which .NET programs run. Native c++ programs run more or less directly on your native platform, i.e., intel/windows.
__________________
Current project: roborally |
|
#3
|
|||
|
|||
|
Thanks for the reply now i got something to choose from, well if i choose the simplest witch(probably spelled wrong
) is FindNextFile function can you give an example? |
|
#4
|
||||
|
||||
|
Well on the msdn page there is a link to a good example:
http://msdn2.microsoft.com/en-us/library/aa365200(VS.85).aspx do not get intimidated by all the windows code, it is really not that difficult but they use a lot of typedefs (DWORD, TCHAR etc.). If that does not help you I'll see if I (or anyone else?) can whip up an example for you. |
|
#5
|
|||
|
|||
|
Thanks for the reply
Ill try to google functions and stuff if i dont understand what it is. |
|
#6
|
|||
|
|||
|
So i do like this?
#include <windows.h> #include <iostream> using namespace std; int _tmain( int argc, TCHAR *argv[]) { HANDLE WINAPI FindFirstFile( LPCTSTR "C:\\*something", LPWIN32_FIND_DATA lpFindFileData ); cout<<lpFindFileData; cin.get(); } |
|
#7
|
|||
|
|||
|
Ok, now i have it like this:
#include <windows.h> #include <iostream> using namespace std; int main( int argc, TCHAR *argv[]) { WIN32_FIND_DATA FindFileData; HANDLE notepad; notepad = FindFirstFile( argv[1], &FindFileData); if ( notepad == INVALID_HANDLE_VALUE) { cout<<"failed to find notepad\n"; cin.get(); } else { cout<<"Found notepad\n"; FindClose(notepad); } } It runs and says "Failed to find notepad", and i dont know where i can declare the path its suppose to search in wich probably is the problem, any suggestions? |
|
#8
|
||||
|
||||
|
On first glance it seems to be the argv[1] (second command line argument) which it cannot find.
|
|
#9
|
|||
|
|||
|
Thanks, i have it declared now:
int main( int argc, TCHAR *argv[]) { WIN32_FIND_DATA FindFileData; HANDLE notepad; argv[1] = "C:\\*"; My last question would be, how do i see the path of of the file it found? I guess i use the GetFullPathName? |
|
#10
|
|||
|
|||
|
Forget about it, its boiling in my brain
To make it simple how do i make it show like a box where the user can select the file path? the one coming up when you are opening files in f.ex notepad. And can i make it open inside a console app if you know what i mean ![]() Wait, found it: OPENFILENAME Structure () ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > [General] Windows file search. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|