????? ?????? ??? ???? ????? ???????? Visual C++

?????? ????????? ?????? ?????????
???? ???????: 307009 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ???? ????? ????? ??? ???? ????? ??????? ????? ?? ???????, ????? ?? ???? ?????? ???????? ???. ????? ??? ?????? ??? ?????? ???????. ????? ????? ????? ??? ???? ????? ????? ?? ??????? ???? ????? ?????? ?????. ????? ?? ??? ?? ????????? ???????? ?? ??? ??????? ?? ??? ????? ????? ????? ????????? ?????? ???.

?????? ??????? ???? I/O ????? ????????. ???? FileSystemObject ????? ??? ?????? ???? ???? ?????? (COM) ???? ?? Visual C++ .NET 2002 ??????? ???? ??? ??????. ???? ?????? FileSystemObject ???? ?????? ?? ????? ??? System.IO ?????? ????? ??? ?????? ??? ??????? ?????????.

???????

???? ??????? ??????? ??????? ?????? ??? ????? ?????? ???????? ?????? ? ??? ??????? ???? ???????:
  • 2005 C++ .NET Microsoft Visual C++ ?? Visual Microsoft

????? ??????? ??????

???? ?????? ??????? ???????? ???????? ?? ????? ????? System::IO. ??? ??? ????? ??? ??? ?????? ?????? ???????? ???????? ???????:
using <mscorlib.dll>
using namespace System;
using namespace System::IO;
????? ????? System::IO ???? ?????? ?????? ?? ????? ?? ??????? ?? ????????. ???? ????? ????? System::IO ??? ??? ?????? ????? ????? ???? ???? ??? ???? ???? ?????? ???????? ??????? ????????. ????? ??? ?????? ????? ????? ???? ????? ??????? ??? ?????? ??? ????? ????? ?? ??? ?????. ??? ???? ??????? ????? ??????? ??? ?????? ?????? ??? ???????? ??????? ??????.

?????? ???????? ???????? ??????? ????? GetDirectories ????? ????? ???? ?????? ???? ?????. ????? ??? ?????? ??? ?????? ???????? ??? ???????? ??????? ?????? C:\ ??? ??? ???? ???:
String* directories[] = Directory::GetDirectories("C:\\");
				
??? ?????? ????? ????? ??? ????? GetFiles. ????? ??????? GetFiles ???????? ????? ????? ?? ??????? ???? ????? ?????? ?????. ????? ????????? ???????? ?????? ?????? ??????? GetFiles ???????? ???? ??????? ?? ?????? C:\ ????? ??? ??? .dll:
String* files[] = Directory::GetFiles("C:\\", "*.dll");
				
????? ??????? ??????? GetDirectories ???????? GetFiles ??? ?????? ???? ????? ????? ?? ??????? ???? ????? ????? ?????. ?????? ??????? ?????? ?????? ?? ???????:
	 void DirSearch(String* sDir)
	 {
		 try
		 {
			 // Find the subfolders in the folder that is passed in.
			 String* d[] = Directory::GetDirectories(sDir);
			 int numDirs = d->get_Length();
			 
			 for (int i=0; i < numDirs; i++)
			 {
				 // Find all the files in the subfolder.
				 String* f[] = Directory::GetFiles(d[i],textBox1->Text);
				 int numFiles = f->get_Length();

				 for (int j=0; j < numFiles; j++)
				 {
					 listBox1->Items->Add(f[j]);
				 }
				 DirSearch(d[i]);
			 }
		 }
		 catch (System::Exception* e)
		 {
			 MessageBox::Show(e->Message);
		 }
	 }
????????? ???????? ??????? ?????? ????? ??? ?????? DirSearch. ??? ?????? ????? ?? ?????? ?????? ?????? ???? ???? ?????. ????? ??????? ??????? GetDirectories ???????? ???????? ??????? ?????? ???? ??? ??????? ??? ??????? ????? ??. ??? ??????? GetDirectories ?????? ???? ? ????? ??????? ????? ?? ????? ??? ?? ???? ????. ??? ???? ???? ??????? ??????? GetFiles ????? ??????? ?? ??? ??????. ??? ????? ???? ???? ???? ??? ??????? ????? ?? ??? ????? GetFiles. ???? ???? ????? ??? ????? ????? ???? ???? ?????? ??????? ???? ????? ??????? GetFiles. ????? ????? ????? ?????? ????? ? ??? ??????? ??? ???? ???????. ??? ???? ???? ???? ??????? ???? DirSearch ??? ???? ?? ?? ????? ???? ????. ????? ??????? ??? ???????? ??????? ????? ?? ???? ???????? ??????? ?? ?????? ????? ???? ?????.

????? ?? ?????

  1. ??? ????? Microsoft Visual Studio .NET 2003 ?? Microsoft Visual Studio 2005.
  2. ?? ??????? ???? ??? ??? ???? ?? ???? ??? ???????.
  3. ??? ????? Project ? ???? ??? Visual C++ .NET.

    ?????? ?? Microsoft Visual C++ 2005 ? ??? ????? Visual C++ .NET ??? Visual C++.
  4. ??? ????? ? ???? ??? ????? ????? Windows (.NET).
  5. ?? ?????? ?????? ???? RecursiveSearchCPP. ?? ???? ?????? ???? C:\ ??? ?? ???? ??? ?????.
  6. ???? ??????? Form1 ?? ????? ???? ?? ???? F4 ???? ?????? "?????".
  7. ?? ?????? "?????" ? ?? ?????? ?????? ?????. ?? ??? ????? ???? 700. ?? ????? ???????? ???? 320.
  8. ????? ????? ???? ??????? ? ???? ???? ???? ?? ???? ???? ???? ????? ???? ???? ???? ListBox ? ???? ???? ?? ??? ??????? Form1 ".
  9. ?? ?????? "?????" ? ?????? ?????????TabIndex ?????? ???? ??? ???:
    ?? ??? ??????????? ??? ??????
    ???? ???? ????????????TabIndex????
    label18, 16144, 165????? ?? ??????? ???? ?????:
    textBox18, 40120 ? 204*.dll
    label28, 96120 ? 253????? ??:
    button1608 ? 24875 ? 250&?????
    listBox1152, 8530 ? 2251
    comboBox18, 128120 ? 252c:\\
  10. ?? ????? InitializeComponent ????? ??????? ?????? ?????? ???????? ???????? ??????? ?????? ???? ?????? ???? ?????? ??? ???? ?????????:
    // Enlist all the network drives that are available on the computer.
    String* p_logicalDrives[] = __gc new String*[];
    comboBox1->Items->Clear();
    p_logicalDrives = Directory::GetLogicalDrives();
    int numDrives = p_logicalDrives->get_Length();
    
    for (int i=0; i< numDrives; i++)
    {
    	comboBox1->Items->Add(p_logicalDrives[i]);
    }
  11. ???? ????? ??????? ??? ?? ????? ?? ?? ???? ???????? ???????? ??????? ?? ???????:
    // Clear the list box.
    listBox1->Items->Clear();
    // You do not have the option to change the values of the files to be searched
    // until the search is completed. Therefore, the following value is false.
    textBox1->Enabled = false;
    comboBox1->Enabled = false;
    
    button1->Text = S"Searching...";
    this->Cursor = Cursors::WaitCursor;
    Application::DoEvents();
    
    // Callthe recursive search method.
    DirSearch(comboBox1->Text);
    button1->Text = S"Search";
    this->Cursor = Cursors::Default;
    
    // After the search is completed, the search criteria is enabled 
    //and you can add other search criteria to search the files recursively.
    textBox1->Enabled = true;
    comboBox1->Enabled = true;
    
  12. ?????? ??????? ???? CTRL + F5 ??????.
  13. ?? ?????? ???????.

????? ????? ????????? ????????

// Form1.h
#pragma once

namespace RecursiveSearchCPP
{
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace System::IO;

	/// <summary> 
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you must change the 
	///          Resource File Name property for the managed resource compiler tool 
	///          that is associated with all .resx files that this class depends on.  Otherwise,
	///          the designers will not be able to interact correctly with localized
	///          resources that are associated with this form.
	/// </summary>
	public __gc class Form1 : public System::Windows::Forms::Form
	{	
	public:
		Form1(void)
		{
			InitializeComponent();
		}
  
	protected:
		void Dispose(Boolean disposing)
		{
			// Form::Dispose(Disposing);
			if (disposing && components)
			{
				components->Dispose();
			}
			__super::Dispose(disposing);
		}
	private: System::Windows::Forms::Label *  label1;
	private: System::Windows::Forms::TextBox *  textBox1;
	private: System::Windows::Forms::Label *  label2;
	private: System::Windows::Forms::Button *  button1;
	private: System::Windows::Forms::ListBox *  listBox1;
	private: System::Windows::Forms::ComboBox *  comboBox1;

	private:
		/// <summary>
		/// This is the required designer variable.
		/// </summary>
		System::ComponentModel::Container * components;

		/// <summary>
		/// This is the required method for Designer support. Do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->label1 = new System::Windows::Forms::Label();
			this->textBox1 = new System::Windows::Forms::TextBox();
			this->label2 = new System::Windows::Forms::Label();
			this->button1 = new System::Windows::Forms::Button();
			this->listBox1 = new System::Windows::Forms::ListBox();
			this->comboBox1 = new System::Windows::Forms::ComboBox();
			this->SuspendLayout();
			// 
			// label1
			// 
			this->label1->Location = System::Drawing::Point(8, 16);
			this->label1->Name = S"label1";
			this->label1->Size = System::Drawing::Size(144, 16);
			this->label1->TabIndex = 5;
			this->label1->Text = S"Search for files containing:";
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(8, 40);
			this->textBox1->Name = S"textBox1";
			this->textBox1->Size = System::Drawing::Size(120, 20);
			this->textBox1->TabIndex = 4;
			this->textBox1->Text = S"*.dll";
			// 
			// label2
			// 
			this->label2->Location = System::Drawing::Point(8, 96);
			this->label2->Name = S"label2";
			this->label2->Size = System::Drawing::Size(120, 23);
			this->label2->TabIndex = 3;
			this->label2->Text = S"Look in:";
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(608, 248);
			this->button1->Name = S"button1";
			this->button1->TabIndex = 0;
			this->button1->Text = S"&Search";
			this->button1->Click += new System::EventHandler(this, button1_Click);
			// 
			// listBox1
			// 
			this->listBox1->Location = System::Drawing::Point(152, 8);
			this->listBox1->Name = S"listBox1";
			this->listBox1->Size = System::Drawing::Size(530, 225);
			this->listBox1->TabIndex = 1;
			// 
			// comboBox1
			//
			// Enlist all the network drives that are available on the computer.
			//
			String* p_logicalDrives[] = __gc new String*[];
			comboBox1->Items->Clear();
			p_logicalDrives = Directory::GetLogicalDrives();
	        int numDrives = p_logicalDrives->get_Length();
			for (int i=0; i< numDrives; i++)
			{
				comboBox1->Items->Add(p_logicalDrives[i]);
			}
			this->comboBox1->Location = System::Drawing::Point(8, 128);
			this->comboBox1->Name = S"comboBox1";
			this->comboBox1->Size = System::Drawing::Size(120, 25);
			this->comboBox1->TabIndex = 2;
			this->comboBox1->Text = S"C:\\";

			// 
			// Form1
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
			this->ClientSize = System::Drawing::Size(688, 286);
			this->Controls->Add(this->comboBox1);
			this->Controls->Add(this->listBox1);
			this->Controls->Add(this->button1);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->label1);
			this->Name = S"Form1";
			this->Text = S"Form1";
			this->ResumeLayout(false);

		}

	private: System::Void button1_Click(System::Object *  sender, System::EventArgs *  e)
	 {
  		//Clears the list box		
  		listBox1->Items->Clear();
  		// You do not have option to change the values of the files to be searched
  		// until the search is completed. Therefore, the value of the following is false.
 	 	textBox1->Enabled = false;
  		comboBox1->Enabled = false;

 	 	button1->Text = S"Searching...";
 		 this->Cursor = Cursors::WaitCursor;
  		Application::DoEvents();

  		// Call the recursive search method.
  		DirSearch(comboBox1->Text);
  		button1->Text = S"Search";
  		this->Cursor = Cursors::Default;
  
  		// After the search is completed, the search criteria is enabled 
  		// and you can add other search criteria to search the files recursively.
  		textBox1->Enabled = true;
  		comboBox1->Enabled = true;
	 }

	 void DirSearch(String* sDir)
	 {
		 try
		 {
			 // Find the subfolders in the folder that is passed in.
			 String* d[] = Directory::GetDirectories(sDir);
			 int numDirs = d->get_Length();
			 
			 for (int i=0; i < numDirs; i++)
			 {
				 // Find all the files in the subfolder.
				 String* f[] = Directory::GetFiles(d[i],textBox1->Text);
				 int numFiles = f->get_Length();

				 for (int j=0; j < numFiles; j++)
				 {
					 listBox1->Items->Add(f[j]);
				 }
				 DirSearch(d[i]);
			 }
		 }
		 catch (System::Exception* e)
		 {
			 System::Console::WriteLine(e->Message);
		 }
	 }
};
}

//Form1.cpp
#include "stdafx.h"
#include "Form1.h"
#include <windows.h>

using namespace RecursiveSearchCPP;

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
	Application::Run(new Form1());
	return 0;
}

?????

????? ?? ????????? ??? ????? ????? ????? Windows ?? ???????? ???? ??? ??????? ?? Visual C++ .NET 2002 ???? ???? "ManagedCWinFormWiz" ?? Visual Studio ??????? .NET.

???????

???? ???????: 307009 - ????? ??? ??????: 15/?????/1428 - ??????: 3.2
????? ???
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
????? ??????: 
kbmt kbhowtomaster kbio KB307009 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????307009

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com