private static extern System.Int32 SHFileOperation(ref SHFILEOPSTRUCT lpFileOp);
// Prepare an SHFILEOPSTRUCT for use, using the properties of this object: private void Prepare(ref SHFILEOPSTRUCT SH, foFileOperation fileOperation, string[] from, string[] to) { // Set Any operation Aborted to FALSE: SH.fAnyOperationsAborted = 0; // No name mappings wanted (TODO) SH.hNameMappings = System.IntPtr.Zero; // Set the parent form handle: if (parentForm == null) { SH.hWnd = System.IntPtr.Zero; } else { SH.hWnd = parentForm.Handle; } // SH.lpszProgressTitle = m_sTitle; -- not supported // Set the flags, add FOR_NOCONFIRMATION if necessary: SH.fFlags = this.flags; if (this.noConfirmation) { SH.fFlags |= (ushort)foFileOperationFlag.FOF_NOCONFIRMATION; } // Build the to and from names from the arrays. Each should be a list of \0-terminated names // with a final \0 terminator at the very end. string fromFile = ""; foreach (string file in from) { fromFile += file + "\0"; } fromFile += "\0"; SH.pFrom = fromFile; // If not deleting, we need another list, this time the To list: if (fileOperation != foFileOperation.FO_DELETE) { if (to != null) { string toFile = ""; foreach (string file in to) { toFile += file + "\0"; } toFile += "\0"; SH.pTo = toFile; } } // Indicate we're using multiple names, if // 1) we have more than one TO file or // 2) we do NOT have a backslash at the end of the only TO file if ((to != null && to.Length > 0) || (to != null && to.Length == 1 && !to[0].EndsWith("\\"))) { SH.fFlags |= (ushort)foFileOperationFlag.FOF_MULTIDESTFILES; } // Set the function code: SH.wFunc = (System.UInt32)fileOperation; }