Home > other >  How to monitor the file update in unity
How to monitor the file update in unity

Time:09-23

Did an android with unity interactive, mobile phone saved a picture to a computer, how to judge image file is updated,

CodePudding user response:

First you need to clear is why do you want?
Monitor file or folder? Listening is a computer or Android?

Whether you mean should be monitored computer folder with the new cell phone to send you from the past that picture?

 
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

The namespace FileWatchered
{
Class Program
{
The static void Main (string [] args)
{
WatcherStrat (@ "folder path", "string");//*. * said to monitor all files folder, ". TXT "monitor some format file
The Console. ReadKey ();
}

Private static void WatcherStrat (string path, the string filter)
{
FileSystemWatcher watcher=new FileSystemWatcher ();

Watcher. Path=Path;

Watcher. Filter=Filter;

Watcher. Changed +=new FileSystemEventHandler (OnProcess);

Watcher. Created +=new FileSystemEventHandler (OnProcess);

Watcher. Does +=new FileSystemEventHandler (OnProcess);

Watcher. Renamed +=new RenamedEventHandler (OnRenamed);

Watcher. EnableRaisingEvents=true;

Watcher. NotifyFilter=NotifyFilters. Attributes | NotifyFilters. CreationTime | NotifyFilters. DirectoryName | NotifyFilters. The FileName | NotifyFilters. LastAccess

. | NotifyFilters LastWrite | NotifyFilters. Security | NotifyFilters. Size;

Watcher. IncludeSubdirectories=true;
}

Private static void OnProcess (object source, FileSystemEventArgs e)
{
If (e.c. with our fabrication: hangeType==WatcherChangeTypes. Created)
{
OnCreated (source, e);
}

Else if (e.c. with our fabrication: hangeType==WatcherChangeTypes. Changed)
{
OnChanged (source, e);
}

Else if (e.c. with our fabrication: hangeType==WatcherChangeTypes. Does)
{
OnDeleted (source, e);
}
}

Private static void OnCreated (object source, FileSystemEventArgs e)
{
Console. WriteLine (" file new event processing logic {0} {1} {2} ", e.c. with our fabrication: hangeType, e.F ullPath, e.N ame);
}

Private static void OnChanged (object source, FileSystemEventArgs e)
{
Console. WriteLine (" file change event processing logic {0} {1} {2} ", e.c. with our fabrication: hangeType, e.F ullPath, e.N ame);
}

Private static void OnDeleted (object source, FileSystemEventArgs e)
{
Console. WriteLine (" file deletion event processing logic {0} {1} {2} ", e.c. with our fabrication: hangeType, e.F ullPath, e.N ame);
}

Private static void OnRenamed (object source, RenamedEventArgs e)
{
Console. WriteLine (" file renaming the event processing logic {0} {1} {2} ", e.c. with our fabrication: hangeType, e.F ullPath, e.N ame);
}
}
}


This is Windows to monitor the file or folder, you change yourself,
  • Related