Welcome 1manik.

That would be doing your homework for you. Read the forum rules.
You need to show effort, and what better way than posting the code that you have tried so far?

But I try to do with this code, but I cant find anything about path. And I hope, that someone can to direct me. I know what most of this commands mean.

Take a look with this

Dim watcher As New FileSystemWatcher()
watcher.Path = "Your Path"

Hope it helps.

So I yet know how it do. But when I debug the program, it write this: An unhandled exception of type System.IndexOutOfRangeException occured in filewatcher.exe. Can you help me?

>An unhandled exception of type System.IndexOutOfRangeException occured in filewatcher.exe. Can you help me?

Exception says that you should have to check array bound or something like that.

>An unhandled exception of type System.IndexOutOfRangeException occured in filewatcher.exe. Can you help me?

Exception says that you should have to check array bound or something like that.

Nice sir..
Thanks for helping our DWMate..
Keep it up Sir.

>An unhandled exception of type System.IndexOutOfRangeException occured in filewatcher.exe. Can you help me?

Exception says that you should have to check array bound or something like that.

Thanks, I found it, but I still dont know why. The problem is in this part:

array<String^ >^args = System::Environment::GetCommandLineArgs(); 

      
      if ( args->Length != 1 ) 
      {
         
         Console::WriteLine( "Usage: Watcher.exe (directory)" );
         return 0;
      }

      
      FileSystemWatcher^ watcher = gcnew FileSystemWatcher; 
      watcher->Path = args[ 1 ];

Hi, so I go forward with this program and it work very good, but I have problem with moving of watched file. I know just like to move strict defined file, but I dont know how can I move file, who is just created. And I dont know, why is Object^sender in this command static void OnChanged( Object ^ sender, FileSystemEventArgs^ e ) ? Can you help me? Thanks
My program see:

#include "stdafx.h" 
#using <System.dll> 

using namespace System; 
using namespace System::IO;
using namespace System::Security::Permissions;


public ref class Watcher 
{
private:
		
   static void OnChanged( Object ^ sender, FileSystemEventArgs^ e ) 
   {																e->ChangeType );
   }
  
   static void OnRenamed( Object ^ sender, RenamedEventArgs^ e ) 
   {
      
      Console::WriteLine( "Súbor: {0} premenovaný na {1}", e->OldFullPath, e->FullPath );
   }

public:
   [PermissionSet(SecurityAction::Demand, Name="FullTrust")] //???
   int static run()
   {
   
	   String^ args = "way";

      
      FileSystemWatcher^ watcher = gcnew FileSystemWatcher; 
	  watcher->Path = args;


      watcher->NotifyFilter = static_cast<NotifyFilters>(NotifyFilters::LastAccess |     
            NotifyFilters::LastWrite | NotifyFilters::FileName | NotifyFilters::DirectoryName);

      
      watcher->Filter = "*.*"; 
      
      watcher->Changed += gcnew FileSystemEventHandler( Watcher::OnChanged ); 
	  watcher->Created += gcnew FileSystemEventHandler( Watcher::OnChanged );
      watcher->Deleted += gcnew FileSystemEventHandler( Watcher::OnChanged ); 
      watcher->Renamed += gcnew RenamedEventHandler( Watcher::OnRenamed );    
	 
	  watcher->EnableRaisingEvents = true;

      // Wait for the user to quit the program.
      Console::WriteLine( "Stlač \'q\' na vypnutie programu." );
      while ( Console::Read() != 'q' );

      return 0;
   }
};

int main()
{
Watcher::run();

String^ path = "C:\\way\\";
String^ path2 = "C:\\way\\";
   try
   {
   
      // Ensure that the target does not exist.
      if ( File::Exists( path2 ) )
            File::Delete( path2 );

      // Move the file.
      File::Move( path, path2 );
      Console::WriteLine( "Súbor {0} bol premiestnený do {1}.", path, path2 );

      // See if the original exists now.
      if ( File::Exists( path ) )
      {
         Console::WriteLine( "Originálny súbor ešte stále existuje." );
      }
      else
      {
         Console::WriteLine( "Originálny súbor už neexistuje" );
      }
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Proces zlyhal: {0}", e );
   }
}

Edited 6 Years Ago by 1manik: n/a

This article has been dead for over six months. Start a new discussion instead.