public override bool Rename(string name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } Drive.ValidateName(name); if (string.Compare(name, Name, StringComparison.OrdinalIgnoreCase) == 0) { return(false); } if (FullPath == null || !Directory.Exists(FullPath)) { return(false); } Directory.Move(FullPath, Path.Combine(Path.GetDirectoryName(FullPath), Id.ToString("N") + "." + ParentId.ToString("N") + "." + name)); return(true); }
public Folder EnsureChildFolder(string name) { Drive.ValidateName(name); string dir = EnsureDirectory(); var item = GetItem(name); if (item != null) { if (item is Folder fld) { return(fld); } throw new InvalidOperationException(); } var folder = new Folder(); folder.FullPath = Path.Combine(dir, Guid.NewGuid().ToString("N") + "." + Id.ToString("N") + "." + name); Directory.CreateDirectory(folder.FullPath); return(folder); }
public Item GetItem(string name) { Drive.ValidateName(name); string dir = Path.GetDirectoryName(FullPath); if (!Directory.Exists(dir)) { return(null); } var file = Directory.EnumerateFileSystemEntries(dir, "*." + Id.ToString("N") + "." + name).FirstOrDefault(); if (file == null) { return(null); } var item = File.Exists(file) ? new Item() : new Folder(); item.FullPath = file; return(item); }