public static bool CopyItems(List <string> items, string destination) { try { var fs = new SHFILEOPSTRUCT { wFunc = FileOperationType.FO_COPY, pFrom = string.Join("\0", items.ToArray()) + '\0' + '\0', pTo = destination + '\0' + '\0' }; SHFileOperation(ref fs); return(true); } catch (Exception) { return(false); } }
private static bool deleteFile(string path, FileOperationFlags flags) { try { var fs = new SHFILEOPSTRUCT { wFunc = FileOperationType.FO_DELETE, pFrom = path + '\0' + '\0', fFlags = flags }; SHFileOperation(ref fs); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Send file to recycle bin /// </summary> /// <param name="path">Location of directory or file to recycle</param> /// <param name="flags">FileOperationFlags to add in addition to FOF_ALLOWUNDO</param> public static bool Send(string path, FileOperationFlags flags) { try { var fs = new SHFILEOPSTRUCT { wFunc = FileOperationType.FO_DELETE, pFrom = path + '\0' + '\0', fFlags = FileOperationFlags.FOF_ALLOWUNDO | flags }; SHFileOperation(ref fs); return(true); } catch (Exception) { return(false); } }
private static extern int SHFileOperation(ref SHFILEOPSTRUCT FileOp);
/// <summary> /// Copies, moves or deletes a filesystem object using shell functionality /// (I.e. shows an OS dialog on overwrite, can move files to the recycle bin, ...) /// </summary> /// <param name="lpFileOp">Descriptor of the file operation to execute</param> /// <returns>An error code. please note that this function has its own set of error codes documented /// here: https://msdn.microsoft.com/en-us/library/windows/desktop/bb762164(v=vs.85).aspx </returns> public virtual int ShellFileOperation(ref SHFILEOPSTRUCT lpFileOp) { throw new NotImplementedException(); }
public static extern int SHFileOperation([In] ref SHFILEOPSTRUCT lpFileOp);