コード例 #1
0
        /// <summary>
        /// Moves a file
        /// </summary>
        /// <param name="sourceFilePath">Full source path</param>
        /// <param name="targetFilePath">Full target path</param>
        public static void MoveFile(PathInfo sourceFilePath, PathInfo targetFilePath)
        {
            if (Win32SafeNativeMethods.MoveFile(sourceFilePath.FullNameUnc, targetFilePath.FullNameUnc))
            {
                return;
            }
            int win32Error = Marshal.GetLastWin32Error();

            NativeExceptionMapping(sourceFilePath.FullName, win32Error);
        }
コード例 #2
0
        /// <summary>
        /// Moves a file
        /// </summary>
        /// <param name="sourceFileName">Full source path</param>
        /// <param name="destFileName">Full target path</param>
        public static void MoveFile(string sourceFileName, string destFileName)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(sourceFileName));
            Contract.Requires(!String.IsNullOrWhiteSpace(destFileName));

            if (!Win32SafeNativeMethods.MoveFile(sourceFileName, destFileName))
            {
                Win32ErrorCodes.NativeExceptionMapping(sourceFileName, Marshal.GetLastWin32Error());
            }
        }
コード例 #3
0
        /// <summary>
        /// Moves a directory
        /// </summary>
        /// <param name="from">Fullname to move</param>
        /// <param name="to">Full targetname</param>
        /// <param name="overwrite">true to overwrite target</param>
        /// <exception cref="DirectoryAlreadyExistsException">Target exists</exception>
        public static void Move(String from, String to, bool overwrite = false)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(from));
            Contract.Requires(!String.IsNullOrWhiteSpace(to));

            if (!overwrite && Exists(to))
            {
                throw new DirectoryAlreadyExistsException("Target directory already exists.", to);
            }

            if (!Win32SafeNativeMethods.MoveFile(from, to))
            {
                int win32Error = Marshal.GetLastWin32Error();
                Win32ErrorCodes.NativeExceptionMapping(from, win32Error);
            }
        }