private void DirectoryInfo_Refresh(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var folder = tempRoot.RandomDirectoryFullPath; var diSysIo = new System.IO.DirectoryInfo(folder + "-System.IO"); var diAlphaFS = new Alphaleonis.Win32.Filesystem.DirectoryInfo(folder + "-AlphaFS"); Console.WriteLine("System.IO Input Directory Path: [{0}]", diSysIo.FullName); Console.WriteLine("AlphaFS Input Directory Path: [{0}]", diAlphaFS.FullName); var existsSysIo = diSysIo.Exists; var exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The directory exists, but is expected not to."); diSysIo.Create(); diAlphaFS.Create(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The directory exists, but is expected not to."); diSysIo.Refresh(); diAlphaFS.Refresh(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsTrue(exists, "The directory does not exists, but is expected to."); diSysIo.Delete(); diAlphaFS.Delete(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsTrue(exists, "The directory does not exists, but is expected to."); diSysIo.Refresh(); diAlphaFS.Refresh(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The directory exists, but is expected not to."); } Console.WriteLine(); }
private void DirectoryInfo_MoveTo_Rename(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var newFolderName = "Rename_to_" + tempRoot.RandomDirectoryName; var dirInfoAlphaFS = new Alphaleonis.Win32.Filesystem.DirectoryInfo(tempRoot.RandomDirectoryFullPath); var dirInfoSystemIO = new System.IO.DirectoryInfo(System.IO.Path.Combine(tempRoot.Directory.FullName, newFolderName)); Console.WriteLine("Input Directory Path: [{0}]", dirInfoAlphaFS.FullName); Console.WriteLine("\n\tRename folder to: [{0}]", dirInfoSystemIO.Name); // Create folder. dirInfoAlphaFS.Create(); // Rename folder. dirInfoAlphaFS.MoveTo(dirInfoSystemIO.FullName); dirInfoAlphaFS.Refresh(); dirInfoSystemIO.Refresh(); Assert.IsTrue(dirInfoAlphaFS.Exists, "It is expected that the source exists, but is does not."); Assert.AreEqual(dirInfoAlphaFS.Parent.FullName, dirInfoSystemIO.Parent.FullName); } Console.WriteLine(); }
private void Directory_Move_Rename(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var folderSrc = System.IO.Directory.CreateDirectory(System.IO.Path.Combine(tempRoot.Directory.FullName, "Source Folder")); var folderDst = new System.IO.DirectoryInfo(System.IO.Path.Combine(tempRoot.Directory.FullName, "Destination Folder")); Console.WriteLine("Input Directory Path: [{0}]\n", folderSrc.FullName); Console.WriteLine("\tRename folder [{0}] to [{1}]", folderSrc.Name, folderDst.Name); Assert.IsTrue(folderSrc.Exists, "The source folder does not exist which was not expected."); Assert.IsFalse(folderDst.Exists, "The destination folder exists which was not expected."); Alphaleonis.Win32.Filesystem.Directory.Move(folderSrc.FullName, folderDst.FullName); folderSrc.Refresh(); folderDst.Refresh(); Assert.IsFalse(folderSrc.Exists, "The source folder exists which was not expected."); Assert.IsTrue(folderDst.Exists, "The destination folder does not exists which was not expected."); } Console.WriteLine(); }
private void Directory_Move_Rename(bool isNetwork) { UnitTestConstants.PrintUnitTestHeader(isNetwork); var tempPath = System.IO.Path.GetTempPath(); if (isNetwork) { tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath); } using (var rootDir = new TemporaryDirectory(tempPath, "Directory.Move (Rename)")) { var folderSrc = System.IO.Directory.CreateDirectory(System.IO.Path.Combine(rootDir.Directory.FullName, "Source-") + System.IO.Path.GetRandomFileName()); var folderDst = new System.IO.DirectoryInfo(System.IO.Path.Combine(rootDir.Directory.FullName, "Destination-") + System.IO.Path.GetRandomFileName()); Console.WriteLine("\nInput Directory Path: [{0}]", folderSrc.FullName); Console.WriteLine("\nRename folder: [{0}] to: [{1}]", folderSrc.Name, folderDst.Name); Assert.IsTrue(folderSrc.Exists, "The source folder does not exist which was not expected."); Assert.IsFalse(folderDst.Exists, "The destination folder exists which was not expected."); Alphaleonis.Win32.Filesystem.Directory.Move(folderSrc.FullName, folderDst.FullName); folderSrc.Refresh(); folderDst.Refresh(); Assert.IsFalse(folderSrc.Exists, "The source folder exists which was not expected."); Assert.IsTrue(folderDst.Exists, "The destination folder does not exists which was not expected."); } Console.WriteLine(); }
public SettingManager() { _cookieFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); _imageHashSerializer = new System.Xml.Serialization.XmlSerializer(typeof(HashSet<string>)); //設定ファイル読み込み EmailAddress = GPlusImageDownloader.Properties.Settings.Default.EmailAddress; Password = GPlusImageDownloader.Properties.Settings.Default.Password; ImageSaveDirectory = new System.IO.DirectoryInfo( string.IsNullOrEmpty(GPlusImageDownloader.Properties.Settings.Default.ImageSaveDirectory) ? Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\testFolder" : GPlusImageDownloader.Properties.Settings.Default.ImageSaveDirectory); Cookies = DeserializeCookie(); ImageHashList = DeserializeHashes(); if (!ImageSaveDirectory.Exists) try { ImageSaveDirectory.Create(); ImageSaveDirectory.Refresh(); } catch (System.IO.IOException) { IsErrorNotFoundImageSaveDirectory = !ImageSaveDirectory.Exists; } else IsErrorNotFoundImageSaveDirectory = false; }
public static void Run(ControllerConfiguration context, Guid versionKey) { var versionsController = new Versions(context); System.IO.DirectoryInfo pushFolder = new System.IO.DirectoryInfo(Program.STR_PUSH_FOLDER); System.IO.DirectoryInfo pullFolder = new System.IO.DirectoryInfo(Program.STR_PULL_FOLDER); versionsController.PushVersion(pushFolder, versionKey); if (!pullFolder.Exists) { pullFolder.Create(); pullFolder.Refresh(); } versionsController.PullVersion(versionKey, pullFolder); pullFolder.Refresh(); var pulledFiles = pullFolder.GetFiles("*", System.IO.SearchOption.AllDirectories); Debug.Assert(pulledFiles.Length == 2); Debug.Assert(pulledFiles.Any(f => f.FullName == String.Format(@"{0}\Subfolder\AnImage.bmp", Program.STR_PULL_FOLDER))); Debug.Assert(pulledFiles.Any(f => f.FullName == String.Format(@"{0}\README.txt", Program.STR_PULL_FOLDER))); }
private void RefreshDirectory() { string path = DataCenter.LogicDataCenter.screenCaptureDataManager.VideoFolderFullPath; if (string.IsNullOrEmpty(path)) { return; } System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(path); if (directoryInfo != null) { directoryInfo.Refresh(); } }
private bool validatingFilesToSend(List <string> filesListPath, out int filesQuantity, out float sizeByte) { sizeByte = 0; filesQuantity = 0; System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo("C:\\AutoSW_PublicityFiles"); if (dirInfo.Exists == true) { dirInfo.Refresh(); //Ensuring the latest changes of the folder System.IO.FileInfo[] fileNames = dirInfo.GetFiles("*.jpg"); int numOfFilesAllowed = 0; if (automaticModeState) { numOfFilesAllowed = 3; //max number of files allowed when automatic mode is ON } else { numOfFilesAllowed = 2147483647; // max number of files allowed for 32-bit integer XD When Automatic is OFF } foreach (System.IO.FileInfo fi in fileNames) { if (sizeByte < 25000000 && filesQuantity < numOfFilesAllowed) { //Console.WriteLine("\nName: {0}, File´s creation time: {1}, Size: {2}", fi.Name, fi.CreationTime, fi.Length); sizeByte += fi.Length; filesQuantity++; filesListPath.Add(fi.Name); } else { return(false); } } if (filesQuantity <= 0) { return(false); } sizeByte /= 1024; sizeByte /= 1024; //Console.WriteLine("\nTOTAL Files: {0}, Size of those files: {1}MB \n\n\n", filesQuantity, sizeByte); return(true); } else { return(false); } }
public void WhereMatchTest() { // TestFolder var a = System.Reflection.Assembly.GetExecutingAssembly(); var folder = new System.IO.DirectoryInfo(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(a.Location), "TestFolder")); var target = new System.IO.DirectoryInfo(System.IO.Path.Combine(this.TestContext.TestRunDirectory, "TestFolder")); var dest = new System.IO.DirectoryInfo(System.IO.Path.Combine(this.TestContext.TestRunDirectory, "DestFolder")); Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(folder.FullName, target.FullName); var results = target.Query(); Debug.WriteLine(""); foreach (var item in results) { Debug.WriteLine(item.RelativePath); } var r2 = results.WhereFileNameMatch(@"(\d)\.xml$"); Debug.WriteLine(""); foreach (var item in r2) { Debug.WriteLine(item.RelativePath); } Assert.AreEqual(2, r2.Count()); Assert.AreEqual(@"XMLFile1.xml", r2.FirstOrDefault()?.RelativePath); Assert.AreEqual(@"NewFolder1\XMLFile2.xml", r2.Skip(1).FirstOrDefault()?.RelativePath); foreach (var item in r2) { item.CopyTo(dest, false); } dest.Refresh(); var destResults = dest.Query(); Debug.WriteLine(""); foreach (var item in destResults) { Debug.WriteLine(item.RelativePath); } }
/// <summary> /// Get IEnumerable<QuerableFilePath> for all of files of a directory recursively. /// This method is eager evaluation. /// </summary> /// <param name="me">The instance of the type which is added this extension method.</param> /// <returns> /// Returns IEnumerable<QuerableFilePath>. /// </returns> public static IEnumerable <QuerableFilePath> Query(this System.IO.DirectoryInfo me) { if (me == null) { throw new ArgumentNullException("me"); } me.Refresh(); var results = new List <QuerableFilePath>(); Action <System.IO.DirectoryInfo, Action <System.IO.DirectoryInfo> > recursion = null; recursion = (folder, exec) => { if (folder.Exists == false) { return; } // end if exec(folder); foreach (var item in folder.GetDirectories()) { recursion(item, exec); } // next item }; recursion(me, (folder) => { results.Add(new QuerableFilePath { RootFolder = me, RelativePath = folder.FullName.Replace(me.FullName, "") }); foreach (var item in folder.GetFiles()) { results.Add(new QuerableFilePath { RootFolder = me, RelativePath = item.FullName.Replace(me.FullName, "") }); } }); return(results); } // end function
/// <summary> /// Creates the correct directory for the instance log files (local copy) /// </summary> /// <returns>Whether the directory exists</returns> protected Boolean MakeInstanceDir() { DateTime Start = Debug.ExecStart; System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(BaseDirectory); if (!di.Exists) { try { di.Create(); di.Refresh(); } catch (Exception Ex) { ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null); } } ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), ""); return(di.Exists); }
static int Main(string[] args) { string filemask = "*"; Console.WriteLine(Environment.Version.ToString()); if (args.Length == 0) { Console.Error.WriteLine("waitforafile.exe <directory> [filemask]"); return(1); } if (!System.IO.Directory.Exists(args[0])) { Console.Error.WriteLine("Directory does not exit!"); return(2); } if (args.Length > 1) { filemask = args[1]; } int existingfiles = 0; System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(Environment.CurrentDirectory); try { d = new System.IO.DirectoryInfo(args[0]); }catch (Exception ex) { Console.Error.WriteLine("Unexpected directory error!"); Console.Error.WriteLine(ex.Message); return(3); } try { existingfiles = d.GetFiles(filemask).Length; }catch (Exception ex) { Console.Error.WriteLine("Unexpected filemask error!"); Console.WriteLine(ex.Message); return(4); } int newfiles = existingfiles; int i = 0; Console.CancelKeyPress += Console_CancelKeyPress; // The below commented out code, will abort waiting when ANY input is sent to this application. This includes piped input. // This may not be ideal, so now it will only abort on ctrl+c //System.IO.Stream consoleinput = Console.OpenStandardInput(); //byte[] buff = new byte[256]; //buff = Enumerable.Repeat((byte)0, 256).ToArray(); //Task<int> t = consoleinput.ReadAsync(buff, 0, 256); while (newfiles == existingfiles) { System.Threading.Thread.Sleep(150); /*if (t.Status == TaskStatus.RanToCompletion) * { * if (t.Result >= 0) * { * if(buff.Contains((byte)3)) * { * // Ctrl+C?? * } * Console.WriteLine("Key pressed, file awaiting aborted."); * break; * } * else * { * throw new Exception("Unexpected task status : Ran to completion, but read no bytes"); * } * }*/ if (abortflag) { return(0); } d.Refresh(); newfiles = d.GetFiles(filemask).Length; i++; if (i >= 50) { System.GC.Collect(0); //probably not needed i = 0; } } return(0); }
private void DirectoryInfo_Refresh(bool isNetwork) { UnitTestConstants.PrintUnitTestHeader(isNetwork); var tempPath = System.IO.Path.GetTempPath(); if (isNetwork) { tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath); } using (var rootDir = new TemporaryDirectory(tempPath, "DirectoryInfo.Refresh")) { var folder = rootDir.RandomFileFullPath; var diSysIo = new System.IO.DirectoryInfo(folder + "-System.IO"); var diAlphaFS = new Alphaleonis.Win32.Filesystem.DirectoryInfo(folder + "-AlphaFS"); Console.WriteLine("\nSystem.IO Input Directory Path: [{0}]", diSysIo.FullName); Console.WriteLine("AlphaFS Input Directory Path: [{0}]", diAlphaFS.FullName); var existsSysIo = diSysIo.Exists; var exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The directory exists, but is expected not to."); diSysIo.Create(); diAlphaFS.Create(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The directory exists, but is expected not to."); diSysIo.Refresh(); diAlphaFS.Refresh(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsTrue(exists, "The directory does not exists, but is expected to."); diSysIo.Delete(); diAlphaFS.Delete(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsTrue(exists, "The directory does not exists, but is expected to."); diSysIo.Refresh(); diAlphaFS.Refresh(); existsSysIo = diSysIo.Exists; exists = diAlphaFS.Exists; Assert.AreEqual(existsSysIo, exists); Assert.IsFalse(exists, "The directory exists, but is expected not to."); } Console.WriteLine(); }
private void buttonConvert_Click(object sender, EventArgs e) { // Create new FormResults dialog which will run the conversion // and display the conversion status and results. FormResults formResults = new FormResults(); // Transmit the conversion settings to FormResults. formResults.recurse = checkBoxIncludeSubfolders.Checked; formResults.conversion = radioButtonEM10.Checked ? Converter.ConversionTarget.EM10 : Converter.ConversionTarget.EM10MarkII; // Validate destination folder. if (radioButtonFolder.Checked) { string destPath = ""; try { // Fully expand the path of the specified destination folder. destPath = System.IO.Path.GetFullPath(textBoxFolder.Text); } catch { // Something wasn't right with the path; notify and exit. MessageBox.Show(Properties.Resources.StringErrorDestination, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); textBoxFolder.Focus(); return; } // Fetch information about the destination directory. System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(destPath); if (!di.Exists) { // Destination directory doesn't exist; ask if we should create it. if (MessageBox.Show(Properties.Resources.StringCreateDestination, this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { // Create the new directory. di.Create(); di.Refresh(); } catch { // Unable to create the new directory; report and exit. MessageBox.Show( Properties.Resources.StringErrorCreateDestination, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); textBoxFolder.Focus(); return; } } else { // User opted not to create new directory; exit. return; } } // Set results directory. formResults.destination = di; } else { formResults.destination = null; } // Overwrite setting only applies if saving output to original location. formResults.overwrite = formResults.destination == null ? checkBoxOverwrite.Checked : false; // Transmit source items. formResults.sourceItems = new string[listBoxSources.Items.Count]; for (int i = 0; i < listBoxSources.Items.Count; i++) { formResults.sourceItems[i] = listBoxSources.Items[i].ToString(); } // FormResults dialog does all the processing. if (formResults.ShowDialog() == DialogResult.OK) { // If success was reported, clear the list of stuff to convert. listBoxSources.Items.Clear(); } }
public void ReplaceEachLineTest() { // TestFolder var a = System.Reflection.Assembly.GetExecutingAssembly(); var folder = new System.IO.DirectoryInfo(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(a.Location), "TestFolder")); var target = new System.IO.DirectoryInfo(System.IO.Path.Combine(this.TestContext.TestRunDirectory, "TestFolder2")); var dest = new System.IO.DirectoryInfo(System.IO.Path.Combine(this.TestContext.TestRunDirectory, "DestFolder2")); Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(folder.FullName, target.FullName); var results = target.Query(); Debug.WriteLine(""); foreach (var item in results) { Debug.WriteLine(item.RelativePath); } var r2 = results.WhereExtensionMatch(@"\.csproj"); Debug.WriteLine(""); foreach (var item in r2) { Assert.AreEqual(true, item.IsMatch(@"(?<sak>\<(SccProjectName|SccLocalPath|SccAuxPath|SccProvider)\>SAK\<\/(SccProjectName|SccLocalPath|SccAuxPath|SccProvider)\>)")); Debug.WriteLine(item.RelativePath); } Assert.AreEqual(1, r2.Count()); Assert.AreEqual(@"NewFolder1\Sample.csproj", r2.FirstOrDefault()?.RelativePath); foreach (var item in r2) { //item.CopyTo(dest, false).ReplaceEachLine( // @"(?<sak>\<(SccProjectName|SccLocalPath|SccAuxPath|SccProvider)\>SAK\<\/(SccProjectName|SccLocalPath|SccAuxPath|SccProvider)\>)", // new { sak=""}); item.CopyTo(dest, false).RemoveMatchedLines( @"(?<sak>\<(SccProjectName|SccLocalPath|SccAuxPath|SccProvider)\>SAK\<\/(SccProjectName|SccLocalPath|SccAuxPath|SccProvider)\>)" ); } dest.Refresh(); var destResults = dest.Query(); Debug.WriteLine(""); foreach (var item in destResults) { if (item.RelativePath.EndsWith(".csproj")) { Assert.AreEqual(false, item.IsMatch(@"(?<sak>\<(SccProjectName|SccLocalPath|SccAuxPath|SccProvider)\>SAK\<\/(SccProjectName|SccLocalPath|SccAuxPath|SccProvider)\>)")); } Debug.WriteLine(item.RelativePath); } var r3 = results.WhereExtensionMatch(@"\.sln"); Debug.WriteLine(""); foreach (var item in r3) { Assert.AreEqual(true, item.IsMatch(@"(?<tfvc>\tGlobalSection\(TeamFoundationVersionControl\)(.+)\tEndGlobalSection)", System.Text.RegularExpressions.RegexOptions.Singleline)); Debug.WriteLine(item.RelativePath); } foreach (var item in r3) { item.CopyTo(dest, false).Replace( @"(?<tfvc>\tGlobalSection\(TeamFoundationVersionControl\)(.+)\tEndGlobalSection)", new { tfvc = "" }, System.Text.RegularExpressions.RegexOptions.Singleline); } var destResults2 = dest.Query(); Debug.WriteLine(""); foreach (var item in destResults2) { if (item.RelativePath.EndsWith(".sln")) { Assert.AreEqual(false, item.IsMatch(@"(?<tfvc>\tGlobalSection\(TeamFoundationVersionControl\)(.+)\tEndGlobalSection)", System.Text.RegularExpressions.RegexOptions.Singleline)); } Debug.WriteLine(item.RelativePath); } } // end function