public static GetParent ( string path ) : System.IO.DirectoryInfo | ||
path | string | |
return | System.IO.DirectoryInfo |
private void tsbImport_Click(object sender, EventArgs e) { if (_fs == null) { return; } var ofd = new OpenFileDialog(); ofd.Title = "Import..."; if (_lastImportExportPath != null) { ofd.InitialDirectory = _lastImportExportPath; } ofd.CheckFileExists = true; ofd.CheckPathExists = true; ofd.Multiselect = true; if (ofd.ShowDialog() == DialogResult.OK) { _lastImportExportPath = IODirectory.GetParent(ofd.FileName).FullName; List <string> _invalidFiles = new List <string>(); using (new WaitCursor(this)) { for (var i = 0; i < ofd.FileNames.Length; i++) { var safename = Path.GetFileName(ofd.FileNames[i]); File file = FindFileByName(safename); if (file == null) { _invalidFiles.Add(safename); } else { byte[] data = IOFile.ReadAllBytes(ofd.FileNames[i]); file.SetData(data); } } } if (_invalidFiles.Count > 0) { var sb = new StringBuilder(); foreach (var s in _invalidFiles) { sb.Append(" " + s + "\n"); } MessageBox.Show("The following files were not found in the archive to be replaced:\n\n" + sb + "\nPlease note that you can not add new files, only replace existing ones. The files must be named exactly " + "as they are in the archive.", "Import", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } PopulateListView(); } }
private bool CreatePresentationThumbnails(string presentationFile) { var temporaryPresentation = Globals.ThisAddIn.Application.Presentations.Open(presentationFile, Core.MsoTriState.msoTrue, Core.MsoTriState.msoTrue, Core.MsoTriState.msoFalse); temporaryPresentation.SaveAs(Directory.GetParent(presentationFile).FullName, PowerPoint.PpSaveAsFileType.ppSaveAsPNG); temporaryPresentation.Close(); return(true); }
private void UpwalkDirectoryTree(FileSystemInfo root) { try { ParentList.Add(root.FullName); var parent = IoDir.GetParent(root.FullName); UpwalkDirectoryTree(parent); } catch (Exception e) { Console.WriteLine(e.Message); } }
public static MSIO.DirectoryInfo GetParent(string path) => MSIOD.GetParent(path);
private void tsbExportSelected_Click(object sender, EventArgs e) { if (_fs == null) { return; } if (lvFiles.SelectedItems.Count == 1) { File file = lvFiles.SelectedItems[0].Tag as File; SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "Export..."; if (_lastImportExportPath != null) { sfd.InitialDirectory = _lastImportExportPath; sfd.FileName = Path.Combine(_lastImportExportPath, file.Name); } else { sfd.FileName = file.Name; } sfd.OverwritePrompt = true; if (sfd.ShowDialog() == DialogResult.OK) { _lastImportExportPath = IODirectory.GetParent(sfd.FileName).FullName; using (new WaitCursor(this)) { byte[] data = file.GetData(); IOFile.WriteAllBytes(sfd.FileName, data); } } } else if (lvFiles.SelectedItems.Count > 1) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "Export Selected..."; fbd.ShowNewFolderButton = true; fbd.SelectedPath = _lastImportExportPath; if (fbd.ShowDialog() == DialogResult.OK) { _lastImportExportPath = fbd.SelectedPath; string path = fbd.SelectedPath; using (new WaitCursor(this)) { foreach (ListViewItem item in lvFiles.SelectedItems) { File file = item.Tag as File; byte[] data = file.GetData(); IOFile.WriteAllBytes(Path.Combine(path, file.Name), data); } } MessageBox.Show("All selected files exported.", "Export Selected", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public void BaselineGetParent() { var actual = Directory.GetParent(Path.Combine(uncDirectory, "system32")); Assert.AreEqual(uncDirectory, actual.FullName); }
public override object invoke() { var session = GetSession(_request); var code = _request["code"].ToString(); var sessionBindings = _sessions[session]; var outWriter = new Writer("out", _request, _client); var errWriter = new Writer("err", _request, _client); // Split the path, and try to infer the ns from the filename. If the ns exists, then change the current ns before evaluating List <String> nsList = new List <String>(); Namespace fileNs = null; try { var path = _request["file"].ToString(); string current = null; while (path != null && current != "Assets") { current = Path.GetFileNameWithoutExtension(path); nsList.Add(current); path = Directory.GetParent(path).FullName; } nsList.Reverse(); nsList.RemoveAt(0); // Debug.Log("Trying to find: " + string.Join(".", nsList.ToArray())); fileNs = Namespace.find(Symbol.create(string.Join(".", nsList.ToArray()))); // Debug.Log("Found: " + string.Join(".", nsList.ToArray())); } catch (Exception e) { /* Whatever sent in :file was not a path. Ignore it */ // Debug.Log(":file was not a valid ns"); } var evalBindings = sessionBindings .assoc(RT.OutVar, outWriter) .assoc(RT.ErrVar, errWriter); if (fileNs != null) { // Debug.Log("Current ns: " + fileNs.ToString()); evalBindings = evalBindings.assoc(RT.CurrentNSVar, fileNs); } Var.pushThreadBindings(evalBindings); try { var form = readStringVar.invoke(readStringOptions, code); var result = Arcadia.Util.Invoke(RT.var("arcadia.repl", "main-thread-eval"), form); var value = (string)prStrVar.invoke(result); star3Var.set(star2Var.deref()); star2Var.set(star1Var.deref()); star1Var.set(result); UpdateSession(session, Var.getThreadBindings()); SendMessage(new BDictionary { { "id", _request["id"] }, { "value", value }, // TODO do we need :values? { "ns", RT.CurrentNSVar.deref().ToString() }, { "session", session.ToString() }, }, _client); outWriter.Flush(); errWriter.Flush(); SendMessage(new BDictionary { { "id", _request["id"] }, { "status", new BList { "done" } }, // TODO does this have to be a list? { "session", session.ToString() }, }, _client); } catch (Exception e) { starEVar.set(e); UpdateSession(session, Var.getThreadBindings()); SendMessage(new BDictionary { { "id", _request["id"] }, { "status", new BList { "eval-error" } }, { "session", session.ToString() }, { "ex", e.GetType().ToString() }, }, _client); SendMessage(new BDictionary { { "id", _request["id"] }, { "session", session.ToString() }, { "err", errorStringVar.invoke(e).ToString() }, }, _client); SendMessage(new BDictionary { { "id", _request["id"] }, { "status", new BList { "done" } }, { "session", session.ToString() }, }, _client); throw; } finally { Var.popThreadBindings(); } return(null); }
public void Button_OnClick() { FilePanel.ShowFolder(Directory.GetParent(FilePanel.CurrentPath).FullName); }
public static Child ToSubsonicSong(this Track track, Album album, Disposition disposition) { var subsonicSong = new Child(); if (album != null) { subsonicSong.Album = album.Name; } subsonicSong.AlbumId = track.AlbumId.ToString("n"); var artist = track.Artists?.FirstOrDefault(); if (artist != null) { subsonicSong.ArtistId = artist.Media.Id.ToString("n"); subsonicSong.Artist = string.Join(Separator, track.Artists.Select(a => a.Media.Name)); } subsonicSong.BitRate = track.Bitrate; subsonicSong.ContentType = track.ContentType; subsonicSong.CoverArt = track.Id.ToString("n"); subsonicSong.Created = track.DateFileCreated; subsonicSong.DiscNumber = track.DiscNumber; subsonicSong.Duration = (int)track.Duration.TotalSeconds; if (track.Genres?.Any() == true) { subsonicSong.Genre = string.Join(Separator, track.Genres.Select(g => g.Name)); } var parentDirectory = Directory.GetParent(track.Path); var grandParentDirectory = Directory.GetParent(parentDirectory.FullName); subsonicSong.Id = track.Id.ToString("n"); subsonicSong.IsDir = false; subsonicSong.IsVideo = false; subsonicSong.Parent = track.AlbumId.ToString("n"); subsonicSong.Path = Path.Combine(grandParentDirectory.Name, parentDirectory.Name, Path.GetFileName(track.Path)).Replace(Path.DirectorySeparatorChar, '/'); subsonicSong.Size = track.Size; if (disposition != null) { subsonicSong.AverageRating = disposition.AverageRating ?? 0.0; if (disposition.Favorited.HasValue) { subsonicSong.Starred = disposition.Favorited.Value; } subsonicSong.UserRating = disposition.UserRating ?? 0; } subsonicSong.Suffix = Path.GetExtension(track.Path); subsonicSong.Title = track.Name; subsonicSong.Track = track.Number; subsonicSong.Type = MediaType.Music; subsonicSong.Year = track.ReleaseDate; return(subsonicSong); }
public static NowPlayingEntry ToSubsonicNowPlayingEntry(this MediaBundle <Track> trackMediaBundle, MediaBundle <Album> albumMediaBundle, Disposition disposition, Playback playback, User user) { var nowPlayingEntry = new NowPlayingEntry(); var track = trackMediaBundle.Media; if (albumMediaBundle != null) { nowPlayingEntry.Album = albumMediaBundle.Media.Name; } nowPlayingEntry.AlbumId = track.AlbumId.ToString("n"); var artist = track.Artists.FirstOrDefault(); if (artist != null) { nowPlayingEntry.ArtistId = artist.Media.Id.ToString("n"); nowPlayingEntry.Artist = string.Join(Separator, track.Artists.Select(a => a.Media.Name)); } nowPlayingEntry.BitRate = track.Bitrate; nowPlayingEntry.ContentType = track.ContentType; nowPlayingEntry.CoverArt = track.Id.ToString("n"); nowPlayingEntry.Created = track.DateFileCreated; nowPlayingEntry.DiscNumber = track.DiscNumber; nowPlayingEntry.Duration = (int)track.Duration.TotalSeconds; if (track.Genres.Count > 0) { nowPlayingEntry.Genre = string.Join(Separator, track.Genres.Select(g => g.Name)); } var parentDirectory = Directory.GetParent(track.Path); var grandParentDirectory = Directory.GetParent(parentDirectory.FullName); nowPlayingEntry.Id = track.Id.ToString("n"); nowPlayingEntry.IsDir = false; nowPlayingEntry.IsVideo = false; nowPlayingEntry.Parent = track.AlbumId.ToString("n"); nowPlayingEntry.Path = Path.Combine(grandParentDirectory.Name, parentDirectory.Name, Path.GetFileName(track.Path)).Replace(Path.DirectorySeparatorChar, '/'); nowPlayingEntry.Size = track.Size; if (disposition != null) { nowPlayingEntry.AverageRating = disposition.AverageRating ?? 0.0; if (disposition.Favorited.HasValue) { nowPlayingEntry.Starred = disposition.Favorited.Value; } nowPlayingEntry.UserRating = disposition.UserRating ?? 0; } nowPlayingEntry.Suffix = Path.GetExtension(track.Path); nowPlayingEntry.Title = track.Name; nowPlayingEntry.Track = track.Number; nowPlayingEntry.Type = MediaType.Music; nowPlayingEntry.Year = track.ReleaseDate; nowPlayingEntry.MinutesAgo = (DateTime.UtcNow - playback.PlaybackDateTime).Minutes; nowPlayingEntry.PlayerName = playback.ClientId; nowPlayingEntry.Username = user.Name; return(nowPlayingEntry); }