C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Iron Speed
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old March 28th, 2008, 11:22 AM
wattamamma wattamamma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 16 wattamamma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 6 sec
Reputation Power: 0
Question [General] Windows file search.

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?

Reply With Quote
  #2  
Old March 28th, 2008, 02:42 PM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Click here for more information.
 
Join Date: Sep 2005
Posts: 595 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 10 h 54 m 18 sec
Reputation Power: 3
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

Reply With Quote
  #3  
Old March 29th, 2008, 06:11 AM
wattamamma wattamamma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 16 wattamamma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 6 sec
Reputation Power: 0
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?

Reply With Quote
  #4  
Old March 29th, 2008, 06:57 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Click here for more information.
 
Join Date: Sep 2005
Posts: 595 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 10 h 54 m 18 sec
Reputation Power: 3
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.

Reply With Quote
  #5  
Old March 29th, 2008, 09:27 AM
wattamamma wattamamma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 16 wattamamma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 6 sec
Reputation Power: 0
Thumbs up

Thanks for the reply Ill try to google functions and stuff if i dont understand what it is.

Reply With Quote
  #6  
Old March 29th, 2008, 11:14 AM
wattamamma wattamamma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 16 wattamamma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 6 sec
Reputation Power: 0
Question

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();
}

Reply With Quote
  #7  
Old March 29th, 2008, 11:57 AM
wattamamma wattamamma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 16 wattamamma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 6 sec
Reputation Power: 0
Question

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?

Reply With Quote
  #8  
Old March 29th, 2008, 12:23 PM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Click here for more information.
 
Join Date: Sep 2005
Posts: 595 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 10 h 54 m 18 sec
Reputation Power: 3
On first glance it seems to be the argv[1] (second command line argument) which it cannot find.

Reply With Quote
  #9  
Old March 30th, 2008, 04:35 AM
wattamamma wattamamma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 16 wattamamma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 6 sec
Reputation Power: 0
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?

Reply With Quote
  #10  
Old March 30th, 2008, 10:10 AM
wattamamma wattamamma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 16 wattamamma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 6 sec
Reputation Power: 0
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 ()

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > [General] Windows file search.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway