private void DeletePreviouslyCreated(File_Containers.FileContainer receiver, IEnumerable <IFileObject> selectedItems) { foreach (IFileObject obj in selectedItems) { if (receiver.StoredDirectory.IsExistsHere(obj.Info.ShortName)) { MessageBoxResult res = MessageBox.Show($"File {obj.Info.ShortName} is already exists in {receiver.StoredDirectory.Info.ShortName}. Replace it?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Question); if (res == MessageBoxResult.Yes) { String path = Path.Combine(receiver.StoredDirectory.Info.FullName, obj.Info.ShortName); List <VFile_Manager.FileObjects.File> filesInDir = receiver.StoredDirectory.GetFiles().ToList(); List <Dir> dirsInDir = receiver.StoredDirectory.GetDirectories().ToList(); IFileObject fileobjToDelete = null; fileobjToDelete = filesInDir.Find((item) => item.Info.ShortName == obj.Info.ShortName); if (fileobjToDelete == null) { fileobjToDelete = dirsInDir.Find((item) => item.Info.ShortName == obj.Info.ShortName); } if (fileobjToDelete != null) { fileobjToDelete.Delete(); } } } } }
/// <summary> /// Writes the specified byte array to the file. If the target file already exists, it is overwritten. /// </summary> /// <param name="file">IFileObject instance</param> /// <param name="bytes">The bytes to write to the file.</param> public static void WriteAllBytes(this IFileObject file, byte[] bytes) { if (file.Type == FileType.File) { file.Delete(); file.CreateFile(); } using (var fs = file.Content.GetStream(FileAccess.Write)) { fs.Write(bytes, 0, bytes.Length); } }
/// <summary> /// <see cref="IFileObject.MoveTo"/> /// </summary> public virtual void MoveTo(IFileObject destFile) { // raise 'before move' LocalFs.OnFileMoving(this, destFile); try { if (destFile is LocalFile) { // delete destination file if (destFile.Type != FileType.Imaginary) { destFile.Delete(); } // use fast API move functions... if (Type == FileType.File) { File.Move(LocalName, ((LocalFile)destFile).LocalName); } if (Type == FileType.Folder) { Directory.Move(LocalName, ((LocalFile)destFile).LocalName); } } else { // copy-delete destFile.CopyFrom(this); this.Delete(); } } catch (Exception ex) { // raise 'error' LocalFs.OnFileError(this, ex); throw new FileSystemException(ex.Message, this, ex); } // raise 'after move' LocalFs.OnFileMoved(this, destFile); }