关于文件的简单操作!!!!!!!!!!ji a!!!

zhoumeifang 2006-06-20 05:44:47
我想把一个文件从一个地方复制到另一个地方,并且要能够确定复制的速率,计算复制的时间,请问该用什么函数啊,多谢了!!!!
...全文
183 9 打赏 收藏 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
fireseed 2006-06-21
  • 打赏
  • 举报
回复
BOOL CopyFileEx(
LPCTSTR lpExistingFileName,
LPCTSTR lpNewFileName,
LPPROGRESS_ROUTINE lpProgressRoutine, <--------注意这里
LPVOID lpData,
LPBOOL pbCancel,
DWORD dwCopyFlags
);

fireseed 2006-06-21
  • 打赏
  • 举报
回复
CopyFileEx

The CopyFileEx function copies an existing file to a new file, notifying the application of its progress through a callback function.


BOOL CopyFileEx(
LPCTSTR lpExistingFileName,
LPCTSTR lpNewFileName,
LPPROGRESS_ROUTINE lpProgressRoutine,
LPVOID lpData,
LPBOOL pbCancel,
DWORD dwCopyFlags
);

Parameters
lpExistingFileName
[in] Pointer to a null-terminated string that specifies the name of an existing file.
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.

Windows Me/98/95: This string must not exceed MAX_PATH characters.
lpNewFileName
[in] Pointer to a null-terminated string that specifies the name of the new file.
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.

Windows Me/98/95: This string must not exceed MAX_PATH characters.
lpProgressRoutine
[in] Address of a callback function of type LPPROGRESS_ROUTINE that is called each time another portion of the file has been copied. This parameter can be NULL. For more information on the progress callback function, see CopyProgressRoutine.
lpData
[in] Argument to be passed to the callback function. This parameter can be NULL.
pbCancel
[in] If this flag is set to TRUE during the copy operation, the operation is canceled. Otherwise, the copy operation will continue to completion.
dwCopyFlags
[in] Flags that specify how the file is to be copied. This parameter can be a combination of the following values. Value Meaning
COPY_FILE_ALLOW_DECRYPTED_DESTINATION An attempt to copy an encrypted file will succeed even if the destination copy cannot be encrypted.
Windows 2000/NT and Windows Me/98/95: This value is not supported.
COPY_FILE_FAIL_IF_EXISTS The copy operation fails immediately if the target file already exists.
COPY_FILE_RESTARTABLE Progress of the copy is tracked in the target file in case the copy fails. The failed copy can be restarted at a later time by specifying the same values for lpExistingFileName and lpNewFileName as those used in the call that failed.

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information call GetLastError.

If lpProgressRoutine returns PROGRESS_CANCEL due to the user canceling the operation, CopyFileEx will return zero and GetLastError will return ERROR_REQUEST_ABORTED. In this case, the partially copied destination file is deleted.

If lpProgressRoutine returns PROGRESS_STOP due to the user stopping the operation, CopyFileEx will return zero and GetLastError will return ERROR_REQUEST_ABORTED. In this case, the partially copied destination file is left intact.

Remarks
This function preserves extended attributes, OLE structured storage, NTFS file system alternate data streams, and file attributes. Security attributes for the existing file are not copied to the new file. To copy security attributes, use the SHFileOperation function.

This function fails with ERROR_ACCESS_DENIED if the destination file already exists and has the FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_READONLY attribute set.



When encrypted files are copied using CopyFileEx, the function attempts to encrypt the destination file with the keys used in the encryption of the source file. If this cannot be done, this function attempts to encrypt the destination file with default keys. If both of these methods cannot be done, CopyFileEx fails with an ERROR_ENCRYPTION_FAILED error code. If you want CopyFileEx to complete the copy operation even if the destination file cannot be encrypted, include the COPY_FILE_ALLOW_DECRYPTED_DESTINATION as the value of the dwCopyFlags parameter in your call to CopyFileEx.

Windows 2000: When encrypted files are copied using CopyFileEx, the function attempts to encrypt the destination file with the default keys. No attempt is made to encrypt the destination file with the keys used in the encryption of the source file. If it cannot be encrypted, CopyFileEx completes the copy operation without encrypting the destination file.


Windows Me/98/95: Although CopyFileEx is not implemented by Windows 98/Me, CopyFileExW is supported by the Microsoft Layer for Unicode.
To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0400 or later. For more information, see Using the SDK Headers.

Requirements
Client Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
Redistributable Requires Microsoft Layer for Unicode on Windows Me/98/95.
Header Declared in Winbase.h; include Windows.h.

Library Link to Kernel32.lib.

DLL Requires Kernel32.dll.
Unicode Implemented as CopyFileExW (Unicode) and CopyFileExA (ANSI).


See Also
CopyFile, CopyProgressRoutine, CreateFile, File Management Functions, MoveFile, MoveFileWithProgress

--------------------------------------------------------------------------------

Last updated: March 2005 | What did you think of this topic? | Order a Platform SDK CD
© Microsoft Corporation. All rights reserved. Terms of use.



Requirements
Client Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
Redistributable Requires Microsoft Layer for Unicode on Windows Me/98/95.
Header Declared in Winbase.h; include Windows.h.

Library Link to Kernel32.lib.

DLL Requires Kernel32.dll.
Unicode Implemented as CopyFileExW (Unicode) and CopyFileExA (ANSI).

See Also
CopyFile, CopyProgressRoutine, CreateFile, File Management Functions, MoveFile, MoveFileWithProgress
Snow_Ice11111 2006-06-21
  • 打赏
  • 举报
回复
简单复制文件可以用一楼朋友的方法,如果还要知道复制速度和进度,以及估算准确时间的话就要用别的方法了。曾见过有朋友自己用文件操作API把文件一部分一部分复制过去,每次复制1K(他的代码适用于网络,所以取值较小,U盘、硬盘复制的话可以分别用64K和512K),然后每秒计算完全多少次操作,可计算出复制速度;进度嘛,把当前复制到的文件位置除以文件大小就行了。我觉得这个方法不错。
一条晚起的虫 2006-06-21
  • 打赏
  • 举报
回复
用CopyFileEx(),里面的回调函数可以。
gudulyn 2006-06-21
  • 打赏
  • 举报
回复
GetTickCount
The GetTickCount function retrieves the number of milliseconds that have elapsed since the system was started
Torch009 2006-06-21
  • 打赏
  • 举报
回复
CopyFileEx
The CopyFileEx function copies an existing file to a new file. This function preserves extended attributes, OLE structured storage, NTFS alternate data streams, and file attributes. Security attributes for the existing file are not copied to the new file.

BOOL CopyFileEx(
LPCWSTR lpExistingFileName,
// pointer to name of an existing file
LPCWSTR lpNewFileName,
// pointer to filename to copy to
LPPROGRESS_ROUTINE lpProgressRoutine,
// pointer to the callback function
LPVOID lpData, // to be passed to the callback function
LPBOOL pbCancel, // flag that can be used to cancel the operation
DWORD dwCopyFlags // flags that specify how the file is copied
);

化外之民 2006-06-21
  • 打赏
  • 举报
回复
try :SHFileOperation
一剑 2006-06-21
  • 打赏
  • 举报
回复
学习楼上:)
xazl 2006-06-20
  • 打赏
  • 举报
回复
BOOL CopyFile(
LPCTSTR lpExistingFileName,
// pointer to name of an existing file
LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists
);
如果要计算时间,我就不知道了。
文件很大的话就猜一个时间呗。

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧