/// <summary> /// Send a file to trash. Moving file to "Hyperspin" or "Rocketlauncher" and placing in correct directory for backup. /// </summary> /// <param name="TrashFolder"></param> /// <param name="file"></param> /// <param name="systemName"></param> /// <param name="column"></param> /// <param name="rom"></param> public static void SendFileToTrash(string TrashFolder, System.IO.FileInfo file, string systemName, string column, string rom) { if (!file.Exists) return false; string PathToMoveTo; if (TrashFolder == "RocketLauncher") PathToMoveTo = AppDomain.CurrentDomain.BaseDirectory + "Rubbish\\" + TrashFolder + "\\" + systemName + "\\" + column + "\\" + rom + "\\"; else PathToMoveTo = AppDomain.CurrentDomain.BaseDirectory + "Rubbish\\" + TrashFolder + "\\" + systemName + "\\" + column + "\\"; DirectoryInfo di = new DirectoryInfo(PathToMoveTo); if (!di.Exists) di.Create(); string moveFilenameNoExt = Path.GetFileNameWithoutExtension(file.FullName); string moveFilenameNew = moveFilenameNoExt; int i = 1; while (File.Exists(PathToMoveTo + moveFilenameNew + file.Extension)) { moveFilenameNew = moveFilenameNoExt + "_" + i; i++; } try { file.MoveTo(PathToMoveTo + moveFilenameNew + file.Extension); string movedFile = PathToMoveTo + moveFilenameNew + file.Extension; return true; } catch (IOException e) { System.Windows.MessageBox.Show( "{0}: Cannot send to rubbish " + "because the file is in use.", e.GetType().Name); return false; } }
private void MarkProcessedFile(System.IO.FileInfo localFile, Config.InputFileMarkingMethods markingMethod) { string targetFileFullName; try { switch (markingMethod) { case Config.InputFileMarkingMethods.FileRename: localFile.MoveTo(localFile.FullName + "-processed"); Utils.MaMessage(String.Format(tsl.T("[PROCFILERENAMED]"), DateTime.Now.ToString(TimeFormat), localFile.Name + "-processed"), Utils.maMessageLineType.WriteLine, Utils.maMessageOutput.ConsoleAndLog, CurrentConfig.LogFile); break; case Config.InputFileMarkingMethods.FileDelete: localFile.Delete(); Utils.MaMessage(String.Format(tsl.T("[PROCFILEDELETED]"), DateTime.Now.ToString(TimeFormat), localFile.Name), Utils.maMessageLineType.WriteLine, Utils.maMessageOutput.ConsoleAndLog, CurrentConfig.LogFile); break; case Config.InputFileMarkingMethods.FileMove: targetFileFullName = CurrentConfig.InputProcessedDirectory + "\\" + localFile.Name; if (System.IO.File.Exists(targetFileFullName)) { System.IO.File.Delete(targetFileFullName); } localFile.MoveTo(targetFileFullName); Utils.MaMessage(String.Format(tsl.T("[PROCFILEMOVED]"), DateTime.Now.ToString(TimeFormat), targetFileFullName), Utils.maMessageLineType.WriteLine, Utils.maMessageOutput.ConsoleAndLog, CurrentConfig.LogFile); break; } } catch (Exception e) { Utils.MaMessage(String.Format(tsl.T("[PROCFILEERROR]"), DateTime.Now.ToString(TimeFormat), e.Message), Utils.maMessageLineType.WriteLine, Utils.maMessageOutput.ConsoleAndLog, CurrentConfig.LogFile); } }
public static System.IO.FileInfo MoveTo(string path, System.IO.FileInfo file) { var root = CommandRunner.Settings.UserDataDirectory; var fullCachePath = System.IO.Path.Combine(root,path,file.Name); file.MoveTo(fullCachePath); return new System.IO.FileInfo(fullCachePath); }