/// <summary> /// Recursive function going through all the folders & trying to find the file by the selector /// </summary> /// <param name="folder"></param> /// <param name="predicate"></param> /// <returns></returns> public GFile FindFileOrFolderInFolder(GFolder folder, Func <GFile, bool> predicate) { GFile result; result = folder.Files.FirstOrDefault(predicate); if (result != null) { return(result); } foreach (GFolder item in folder.Folders) { if (predicate(item)) { return(item); } GFile r = FindFileOrFolderInFolder(item, predicate); if (r != null) { return(r); } } return(null); }
public void CopyFile(GFile source, GFolder destination, string newFileName) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (destination == null) { throw new ArgumentNullException(nameof(destination)); } var fileCopyRequest = this.Service.Files.Copy(new File() { Parents = new string[] { destination?.FileInfo?.Id }, Name = newFileName }, source.FileInfo.Id); if (!string.IsNullOrEmpty(DriveId)) { fileCopyRequest.SupportsTeamDrives = true; fileCopyRequest.SupportsAllDrives = false; } else { fileCopyRequest.SupportsTeamDrives = true; fileCopyRequest.SupportsAllDrives = true; } //var fileCopyRequest = this.Service.Files.Copy(source.FileInfo, source.FileInfo.Id); fileCopyRequest.Execute(); }
private string getNameWithParentPath(GFile file) { if (file == null) { return(""); } return(getNameWithParentPath(file.GParent) + @"/" + file.Name); }
public bool IsParentOf(GFile possibleChild) { var parents = possibleChild?.FileInfo?.Parents; if (parents == null || parents.Count > 1 || parents.Count == 0) { return(false); } return(this.FileInfo.Id == parents.First()); }