移动文件

/// <summary>
        /// Moves an existing file or directory, including its children, with various move options.
        /// The MoveFileWithProgress function is equivalent to the MoveFileEx function, except that MoveFileWithProgress allows you to provide a callback function that receives progress notifications.
        /// To perform this operation as a transacted operation, use the MoveFileTransacted function.
        /// </summary>
        /// <param name="lpExistingFileName">The current name of the file or directory on the local computer.
        /// If dwFlags specifies MOVEFILE_DELAY_UNTIL_REBOOT, the file cannot exist on a remote share, because delayed operations are performed before the network is available.
        /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File</param>
        /// <param name="lpNewFileName">The new name of the file or directory on the local computer.
        /// When moving a file, the destination can be on a different file system or volume. If the destination is on another drive, you must set the MOVEFILE_COPY_ALLOWED flag in dwFlags.
        /// When moving a directory, the destination must be on the same drive.
        /// If dwFlags specifies MOVEFILE_DELAY_UNTIL_REBOOT and lpNewFileName is NULL, MoveFileEx registers the lpExistingFileName file to be deleted when the system restarts. If lpExistingFileName refers to a directory, the system removes the directory at restart only if the directory is empty.</param>
        /// <param name="dwFlags"></param>
        /// <returns>If the function succeeds, the return value is nonzero.</returns>
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, MoveFile dwFlags);

        public enum MoveFile : uint
        {
            /// <summary>
            /// If the file is to be moved to a different volume, the function simulates the move by using the CopyFile and DeleteFile functions.
            /// If the file is successfully copied to a different volume and the original file is unable to be deleted, the function succeeds leaving the source file intact.
            /// This value cannot be used with MOVEFILE_DELAY_UNTIL_REBOOT.
            /// </summary>
            MOVEFILE_COPY_ALLOWED = 0x2,
            /// <summary>
            /// Reserved for future use.
            /// </summary>
            MOVEFILE_CREATE_HARDLINK = 0x10,
            /// <summary>
            /// The system does not move the file until the operating system is restarted. The system moves the file immediately after AUTOCHK is executed, but before creating any paging files. Consequently, this parameter enables the function to delete paging files from previous startups.
            /// This value can be used only if the process is in the context of a user who belongs to the administrators group or the LocalSystem account.
            /// This value cannot be used with MOVEFILE_COPY_ALLOWED.
            /// Windows Server 2003 and Windows XP:  For information about special situations where this functionality can fail, and a suggested workaround solution, see Files are not exchanged when Windows Server 2003 restarts if you use the MoveFileEx function to schedule a replacement for some files in the Help and Support Knowledge Base.
            /// </summary>
            MOVEFILE_DELAY_UNTIL_REBOOT = 0x4,
            /// <summary>
            /// The function fails if the source file is a link source, but the file cannot be tracked after the move. This situation can occur if the destination is a volume formatted with the FAT file system.
            /// </summary>
            MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20,
            /// <summary>
            /// If a file named lpNewFileName exists, the function replaces its contents with the contents of the lpExistingFileName file, provided that security requirements regarding access control lists (ACLs) are met. For more information, see the Remarks section of this topic.
            /// This value cannot be used if lpNewFileName or lpExistingFileName names a directory.
            /// </summary>
            MOVEFILE_REPLACE_EXISTING = 0x1,
            /// <summary>
            /// The function does not return until the file is actually moved on the disk.
            /// Setting this value guarantees that a move performed as a copy and delete operation is flushed to disk before the function returns. The flush occurs at the end of the copy operation.
            /// This value has no effect if MOVEFILE_DELAY_UNTIL_REBOOT is set.
            /// </summary>
            MOVEFILE_WRITE_THROUGH = 0x8

        }

 

转载于:https://www.cnblogs.com/wjshan0808/p/4241385.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值