/// <summary> /// Gets a list of all the currently selected files/folders /// </summary> /// <returns>A list of currently selected files</returns> public static List <FolderItem> SelectedPaths() { var activeHandle = GetForegroundWindow(); var selected = new List <FolderItem>(); foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows()) { if (window.HWND != (int)activeHandle) { continue; } var filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower(); if (filename.ToLowerInvariant() == EXPLORER_NAME) { Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems(); foreach (Shell32.FolderItem item in items) { selected.Add(FromShellFolderItem(item)); } } } //GetItemsInSelectedPath(); return(selected); }
/// <summary> /// 功能:解压zip格式的文件。 /// </summary> /// <param name="zipFilePath">压缩文件路径</param> /// <param name="unZipDir">解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹</param> /// <param name="err">出错信息</param> /// <returns>解压是否成功</returns> public static bool UnZipFile(string zipFilePath, string unZipDir, out string err) { err = ""; if (zipFilePath.Length == 0) { err = "压缩文件不能为空!"; return(false); } else if (!zipFilePath.EndsWith(".zip")) { err = "文件格式不正确!"; return(false); } else if (!System.IO.File.Exists(zipFilePath)) { err = "压缩文件不存在!"; return(false); } //解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹 if (unZipDir.Length == 0) { unZipDir = zipFilePath.Replace(System.IO.Path.GetFileName(zipFilePath), System.IO.Path.GetFileNameWithoutExtension(zipFilePath)); } if (!unZipDir.EndsWith("\\")) { unZipDir += "\\"; } if (!System.IO.Directory.Exists(unZipDir)) { System.IO.Directory.CreateDirectory(unZipDir); } try { Shell32.ShellClass sc = new Shell32.ShellClass(); Shell32.Folder SrcFolder = sc.NameSpace(zipFilePath); Shell32.Folder DestFolder = sc.NameSpace(unZipDir); Shell32.FolderItems items = SrcFolder.Items(); DestFolder.CopyHere(items, 20); } catch (Exception ex) { err = ex.Message; return(false); } return(true); }//解压结束
private static async void Deck_KeyStateChanged(object sender, KeyEventArgs e) { if (e.IsDown) { switch (e.Key) { case 0: Console.Write(e.Key); Console.WriteLine(" - Trondheim Ballklubb"); break; case 1: Console.Write(e.Key); Console.WriteLine(" - Smiley"); break; case 4: _quitEvent.Set(); break; case 10: string filename; ArrayList selected = new ArrayList(); foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows()) { filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower(); if (filename.ToLowerInvariant() == "explorer") { Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems(); foreach (Shell32.FolderItem item in items) { selected.Add(item.Path); } } } foreach (var file in selected) { Console.WriteLine(file); } break; case 11: //System.Windows.Clipboard break; case 14: if (sender is IStreamDeck deck) { Console.WriteLine("-----------------------"); for (ushort i = 0; i <= byte.MaxValue; i++) { deck.SetKeyBitmap(14, KeyBitmap.FromRGBColor((byte)i, (byte)(byte.MaxValue - i), (byte)i)); await Task.Delay(10); Console.WriteLine(i); } } break; default: Console.WriteLine(e.Key); break; } } }