91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

c++文件監控之FileSystemWatcher

發布時間:2020-08-22 07:12:27 來源:腳本之家 閱讀:229 作者:mdxy-dxy 欄目:編程語言

具體代碼如下:

#using <System.dll>
#include <iostream>

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

public ref class Watcher
{
private:
  // Define the event handlers.
  static void OnChanged( Object^ /*source*/, FileSystemEventArgs^ e )
  {
   // Specify what is done when a file is changed, created, or deleted.
   Console::WriteLine( "File: {0} {1}", e->FullPath, e->ChangeType );
  }

  static void OnRenamed( Object^ /*source*/, RenamedEventArgs^ e )
  {
   // Specify what is done when a file is renamed.
   Console::WriteLine( "File: {0} renamed to {1}", e->OldFullPath, e->FullPath );
  }

public:
  [PermissionSet(SecurityAction::Demand, Name="FullTrust")]
  int static run()
  {
   //array<String^>^args = System::Environment::GetCommandLineArgs();
   //創建一個FileSystemWatcher并設置它的屬性.
   FileSystemWatcher^ fsWatcher = gcnew FileSystemWatcher( );
   fsWatcher->Path = "C:\\files";

   /* Watch for changes in LastAccess and LastWrite times, and
     the renaming of files or directories. */
   fsWatcher->NotifyFilter = static_cast<NotifyFilters>(//監聽文件的以下屬性 按需求添加 這里我添加了一些常用的
                NotifyFilters::LastAccess | //文件或文件夾上一次打開的日期。 
                NotifyFilters::LastWrite | //上一次向文件或文件夾寫入內容的日期
                NotifyFilters::FileName | //文件名
                NotifyFilters::DirectoryName | //目錄名
                NotifyFilters::Size); //大小

   //監聽子目錄
   fsWatcher->IncludeSubdirectories = true;
   // Only watch text files.
   //fsWatcher->Filter = "*.txt";

   // Add event handlers.
   fsWatcher->Changed += gcnew FileSystemEventHandler( Watcher::OnChanged );
   fsWatcher->Created += gcnew FileSystemEventHandler( Watcher::OnChanged );
   fsWatcher->Deleted += gcnew FileSystemEventHandler( Watcher::OnChanged );
   fsWatcher->Renamed += gcnew RenamedEventHandler( Watcher::OnRenamed );

   // Begin watching.
   fsWatcher->EnableRaisingEvents = true;

   // Wait for the user to quit the program.
   Console::WriteLine( "Press \'q\' to quit the sample." );
   while ( Console::Read() != 'q' );

   return 0;
  }
};

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

過程 1.首先創建FileSystemWatcher 對象  用來設置一些屬性以及添加監聽事件

   2.設置監聽目錄

   3.設置監聽文件的屬性

   4.設置監聽子目錄

   5.添加監聽事件

   6.開始監聽

上面的sample代碼可以在MSDN上找到,如果有不確定的地方,可以查看文檔

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

安图县| 福清市| 牡丹江市| 辰溪县| 洪江市| 库尔勒市| 旌德县| 固安县| 弥渡县| 和政县| 舞阳县| 旅游| 龙州县| 石景山区| 阳西县| 大兴区| 闽清县| 永善县| 收藏| 乐亭县| 太湖县| 云和县| 夏津县| 灵川县| 竹山县| 通许县| 梅州市| 衢州市| 平顺县| 布尔津县| 玉门市| 五华县| 隆尧县| 高台县| 瑞金市| 长治县| 蓬溪县| 奉贤区| 蒲城县| 郎溪县| 秭归县|