The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled C# Code
Posted by: jimmuy | February 13, 2011 @ 1:57pm
C# Code
[
Download
]
WatchForFile mw = new WatchForFile(); List<WatchForFile> monitorThese = new List<WatchForFile>(); List <String> extensions = new List<String>(textBoxOtherextensions.Text.Split(',')); /*string[] extensionsarray */ // extensions.AddRange((int).Length) foreach (String s in extensions){ WatchForFile mwf= new WatchForFile(); mwf.watchThisFile(Properties.Settings.Default.Path, "*." + s); monitorThese.Add(mwf); } public void OnRenamed(object sender, FileSystemEventArgs e) { try { FileInfo thisFile = new FileInfo(e.FullPath); System.Windows.MessageBox.Show("Filens Directory.Name = " +thisFile.Directory.Name+Environment.NewLine+"Filens thisFile.DirectoryName = " + thisFile.DirectoryName); System.IO.DirectoryInfo myPath = new System.IO.DirectoryInfo(thisFile.DirectoryName); FileInfo[] filearray = myPath.GetFiles(); List<FileInfo> dirFiles = new List<FileInfo>(); foreach(FileInfo f in filearray){ dirFiles.Add(f); } FileInfo utExtension = dirFiles.Find(delegate(FileInfo f) { return f.Extension == "!ut"; }); //Person myLocatedObject = myList.Find(delegate(Person p) {return p.ID == 1; }); // Best way for finding an object. if (utExtension != null) { Properties.Settings.Default.Log += Environment.NewLine + "Change detected, but !ut extension found. Doing nothing..."; } else { Properties.Settings.Default.Log += "Change detected, and no !ut extensions found. Trying to unzip..."; SevenZipExtractor.SetLibraryPath(@"..\7z.dll"); string fileName = e.FullPath.ToString(); string directory = Properties.Settings.Default.Destination+thisFile.Directory.Name; var extractor = new SevenZipExtractor(fileName); extractor.Extracting += new EventHandler<ProgressEventArgs>(extr_Extracting); extractor.FileExtractionStarted += new EventHandler<FileInfoEventArgs>(extr_FileExtractionStarted); extractor.FileExists += new EventHandler<FileOverwriteEventArgs>(extr_FileExists); extractor.ExtractionFinished += new EventHandler<EventArgs>(extr_ExtractionFinished); extractor.BeginExtractArchive(directory); } } catch (Exception error) { System.Windows.MessageBox.Show("error: "+error.ToString()); } } public class WatchForFile { FileSystemWatcher fmw = new FileSystemWatcher(); public string watchThisFile(string path, string filter) { try { fmw.IncludeSubdirectories = true; fmw.Filter = filter; fmw.Path = path; fmw.NotifyFilter = NotifyFilters.FileName; fmw.EnableRaisingEvents = true; // Add event handlers. fmw.Renamed += new RenamedEventHandler(OnRenamed); return "Started Monitoring!"; } catch (Exception error) { return error.ToString(); } } public string path { get { return fmw.Path; } } public string filter { get { return fmw.Filter; } } public virtual void OnRenamed(object sender, FileSystemEventArgs e){} }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.49 / 8
49 Votes
http://codebin.yi.org/1119
page generated in 0.00 seconds