예제 #1
0
		/// <summary>
		/// Copies a file from one place to another, using the Shell file copying routines.
		/// </summary>
		/// <param name="windowHandle">Parent form's handle.</param>
		/// <param name="source">Source path.</param>
		/// <param name="destination">Destination path.</param>
		/// <param name="progressTitle">Title of progress bar.</param>
		/// <param name="aborted">Was the operation aborted?</param>
		public static void CopyFileOrDirectory(IntPtr windowHandle, string source, string destination, string progressTitle, ref bool aborted)
		{
			int retval = 0;
			var shf = new Win32API.Shell32.SHFILEOPSTRUCT();
			shf.wFunc = Win32API.Shell32.FO_COPY;
			shf.fFlags = Win32API.Shell32.FOF_SIMPLEPROGRESS;
			shf.lpszProgressTitle = progressTitle;
            if (windowHandle != IntPtr.Zero)
            {
                shf.hwnd = windowHandle;
            }
			shf.pFrom = source + "\0";
			shf.pTo = destination + "\0";
			shf.fAnyOperationsAborted = false;
			retval = Win32API.Shell32.SHFileOperation(ref shf);
			aborted = (retval != 0) || shf.fAnyOperationsAborted;
		}
예제 #2
0
		/// <summary>
		/// Deletes files.
		/// </summary>
		/// <param name="form">Parent form.</param>
		/// <param name="paths">Full paths to files or folders (no mixing and matching).</param>
		/// <param name="aborted">Was the operation aborted?</param>
        public static void DeleteFilesOrDirectories(IntPtr windowHandle, IEnumerable<string> paths, String progressTitle, ref Boolean aborted)
		{
            var delimitedPaths = string.Join("\0", paths.ToArray());
            
			int retval = 0;
			var shf = new Win32API.Shell32.SHFILEOPSTRUCT();
            shf.wFunc = Win32API.Shell32.FO_DELETE;
            shf.fFlags = Win32API.Shell32.FOF_ALLOWUNDO | Win32API.Shell32.FOF_NOCONFIRMATION;
            shf.lpszProgressTitle = progressTitle;
            shf.hwnd = IntPtr.Zero;
            if (windowHandle != IntPtr.Zero)
            {
                shf.hwnd = windowHandle;
            }
            shf.pFrom = delimitedPaths + "\0";
            shf.pTo = "\0";
			shf.fAnyOperationsAborted = false;
			retval = Win32API.Shell32.SHFileOperation(ref shf);
			aborted = (retval != 0) || shf.fAnyOperationsAborted;
		}