void explorerListView1_AfterLabelEdit(object sender, LabelEditEventArgs e) { ShellItem item = (ShellItem)explorerListView1.SelectedItems[0].Tag; String from = item.Path; if (Regex.IsMatch(from, @"^[a-z]:\\\w+", RegexOptions.IgnoreCase)) { String to = item.Parent.Path + "\\" + e.Label; ShellAPI.SHFILEOPSTRUCT fileOp = new ShellAPI.SHFILEOPSTRUCT(); fileOp.hwnd = ParentForm.Handle; fileOp.wFunc = ShellAPI.FO_Func.RENAME; fileOp.pFrom = Marshal.StringToHGlobalUni(from + '\0'); fileOp.pTo = Marshal.StringToHGlobalUni(to + '\0'); ShellAPI.SHFileOperation(ref fileOp); } }
private void DeleteSelected() { if (explorerListView1.SelectedItems.Count > 0) { String[] files = GetSelectedForDelete(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < files.Length; i++) { sb.Append(files[i] + '\0'); } sb.Append('\0'); ShellAPI.SHFILEOPSTRUCT fileOp = new ShellAPI.SHFILEOPSTRUCT(); fileOp.hwnd = ParentForm.Handle; fileOp.wFunc = ShellAPI.FO_Func.DELETE; fileOp.pFrom = Marshal.StringToHGlobalUni(sb.ToString()); ShellAPI.SHFileOperation(ref fileOp); RefreshExplorer(); } }
private void FileOperation(String src, String dest, bool cut) { if (String.Compare(src, dest, true) != 0) { ShellAPI.SHFILEOPSTRUCT fileOp = new ShellAPI.SHFILEOPSTRUCT(); fileOp.hwnd = ParentForm.Handle; if (cut) { fileOp.wFunc = ShellAPI.FO_Func.MOVE; } else { fileOp.wFunc = ShellAPI.FO_Func.COPY; } fileOp.pFrom = Marshal.StringToHGlobalUni(src + '\0'); fileOp.pTo = Marshal.StringToHGlobalUni(dest + '\0'); ShellAPI.SHFileOperation(ref fileOp); } }