|
Hi,
Gud its a great job.
But here only copy create of source file,there is no option for file replacing if it is already exist.
Please tell me how i do this.
How can replace new one with existin one.
Thanks in advance.
|
|
|
|
|
"_$h@nky_" wrote: Please tell me how i do this.
Have you tried changing arguments 3, 6, and 8? have you tried using SHFileOperation() directly to see how it behaves?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
After going through all the bother of writing this wrapper, you might wanna add some more detailed return codes. MSDN says you sould only check whether the returned value is 0 or not, and that GetLastError is not used. However, you can find the list of actual codes here:
http://shellrevealed.com/blogs/shellblog/archive/2006/09/11/Common-Questions-Concerning-the-SHFileOperation-API_3A00_-Part-1.aspx[^]
I'd suggest putting them all into an internal enum rather than just defining them - will make it easier to understand the return code within the debugger. Also, I've already recieved a return code that wasn't among the ones described in the blog - you might wanna describe them as hints or so, without any guarantee. Will still be more useful than only checking for 0.
Eran
|
|
|
|
|
Indeed, well done.
An easy 5.
|
|
|
|
|
Great wrapper, thanks for your good work. But I have got a problem, when showing a custom error message, because I would like to suppress the error messages from SHFileOperation totally, and they always show up. Any ways to suppress them ?
All the label says is that this stuff contains chemicals "... known to the State of California to cause cancer in rats and low-income test subjects." Roger Wright http://www.codeproject.com/lounge.asp?select=965687&exp=5&fr=1#xx965687xx
|
|
|
|
|
|
Works great... thank you.
All the label says is that this stuff contains chemicals "... known to the State of California to cause cancer in rats and low-income test subjects." Roger Wright http://www.codeproject.com/lounge.asp?select=965687&exp=5&fr=1#xx965687xx
|
|
|
|
|
Hello!
Is it possible to specify the size and position of the dialog?
Thanks for your help!
|
|
|
|
|
Since that feature isn't present in the interface, there's no way to access the position
--
I'm Michael Dunn and I approve this post.
Vote Trogdor in oh-four!
|
|
|
|
|
Try the following. Becarefull. If another Copy-Dialog is in use, this may catch the false one.
<br />
#define CSF_MOVE_WINDOW 0x00000001<br />
#define CSF_DISABLE_CANCEL 0x00000002<br />
typedef struct CHANGE_COPYDLG_DATA_st<br />
{<br />
RECT rc;<br />
DWORD dwFlags;<br />
}CHANGE_COPYDLG_DATA, *LPCHANGE_COPYDLG_DATA;<br />
then from your code call ChangeCopyDlg before calling Go(...);
<br />
LPCHANGE_COPYDLG_DATA pData = new CHANGE_COPYDLG_DATA();<br />
GetRect4CopyDlg( &pData->rc);<br />
pData->dwFlags = CSF_DISABLE_CANCEL|CSF_MOVE_WINDOW|CSF_COLLECT_GARBAGE;<br />
DWORD dwThreadID;<br />
CreateThread( NULL, NULL, ChangeCopyDlg, NULL, NULL, &dwThreadID);<br />
<br />
DWORD WINAPI CCopy::ChangeCopyDlg( LPVOID lpParameter)<br />
{<br />
LPCHANGE_COPYDLG_DATA pData = lpParameter;<br />
if( pData == NULL) return 0;
m_strCaption = "Kopieren..."
<br />
<br />
HWND hWnd = FindWindow( "", m_strCaption);<br />
HWND hWndTitle = NULL;<br />
<br />
<br />
int iElapsed = 0;
while( !hWnd && iElapsed++ < 100 && m_bContinue)<br />
{<br />
Sleep(100);<br />
<br />
hWnd = FindWindowEx( NULL, hWnd, NULL, m_strCaption);<br />
if( hWnd )<br />
{<br />
hWndTitle = FindWindowEx( hWnd, NULL, NULL, m_strMessage);<br />
if( hWndTitle )<br />
break;<br />
else<br />
hWnd = NULL;<br />
}<br />
}<br />
<br />
<br />
if( hWndTitle )<br />
{<br />
if( pData->dwFlags & CSF_DISABLE_CANCEL)<br />
{<br />
HWND hCancelBtn = FindWindowEx( hWnd, NULL, "BUTTON", NULL);<br />
if( hCancelBtn )<br />
{<br />
EnableWindow( hCancelBtn, FALSE);<br />
ShowWindow(hCancelBtn, SW_HIDE);<br />
return 1;<br />
}<br />
}<br />
<br />
if( pData->dwFlags & CSF_MOVE_WINDOW )<br />
{<br />
MoveWindow( hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, TRUE);<br />
}<br />
<br />
}<br />
<br />
if( pData->dwFlags & CSF_COLLECT_GARBAGE)<br />
{<br />
delete pData;<br />
pData = NULL;<br />
}<br />
<br />
return 0;<br />
}<br />
-- modified at 9:04 Tuesday 27th September, 2005
|
|
|
|
|
paste the following into the class declaration to make setting the flags a bit easier:
protected:
void IntSetFlag(DWORD flag, bool on)
{
if (on)
m_rFOS.fFlags |= flag;
else
m_rFOS.fFlags &= ~flag;
}
public:
CShellFileOp & Silent(bool on = true) { IntSetFlag(FOF_SILENT, on); return *this; }
CShellFileOp & AllowUndo(bool on = true) { IntSetFlag(FOF_ALLOWUNDO, on); return *this; }
CShellFileOp & FilesOnly(bool on = true) { IntSetFlag(FOF_FILESONLY, on); return *this; }
CShellFileOp & NoConfirmation(bool on = true) { IntSetFlag(FOF_NOCONFIRMATION, on); return *this; }
CShellFileOp & NoConfirmMkDir(bool on = true) { IntSetFlag(FOF_NOCONFIRMMKDIR, on); return *this; }
CShellFileOp & RenameOnCollision(bool on = true){ IntSetFlag(FOF_RENAMEONCOLLISION, on); return *this; }
CShellFileOp & SimpleProgress(bool on = true) { IntSetFlag(FOF_SIMPLEPROGRESS, on); return *this; }
Note: returning a reference to self allows chaining of the flag setting, as this:
sfo.Silent().AllowUndo();
Note2: Michael: If you like to include it in your code, feel free
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygen
|
|
|
|
|
I am using this class to clean a directory, everything works fine just one more thing i want to add
i want to be able to show a progress bar to the user NOT the default one but the one which i have on a dialog
do i get some sort of notifications from shell as it removes the files
i also want to show the disk space freed
thanks for sharing the code
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
Is it possible to force the display of the dialog during one copy even for a single file copy ?
Programming is not an end in itself but only a means to an end
|
|
|
|
|
When building project using Visual Studio 2003 I get these four errors from CShellFileOp.cpp:
-
CShellFileOp.cpp(80): error C2316: 'CMemoryException' : cannot be caught as the destructor and/or copy constructor are inaccessible
-
CShellFileOp.cpp(115): error C2316: 'CMemoryException' : cannot be caught as the destructor and/or copy constructor are inaccessible
-
CShellFileOp.cpp(297): error C2316: 'CMemoryException' : cannot be caught as the destructor and/or copy constructor are inaccessible
-
CShellFileOp.cpp(488): error C2316: 'CMemoryException' : cannot be caught as the destructor and/or copy constructor are inaccessible
-
They all are from catch-lines like in CShellFileOp::AddSourceFile:
try
{
m_lcstrSourceFiles.AddTail ( szPath );
}
catch ( CMemoryException )
{
TRACE0("Memory exception in CShellFileOp::AddSourceFile()!\n");
throw;
}
[Edit: removed my own change from code]
|
|
|
|
|
|
Why is it that when I delete my files with the wrapper (send the files to the Recycle Bin), I find that the files I deleted are in the Recycle Bin but all their filenames are blank?
I've checked the SourceBufferSize and szzSourceFiles and they appear to be correct.
Thanks.
|
|
|
|
|
How can I get SHFileOperation to copy files from a network drive onto a local folder? I have tried the following:
SHFILEOPSTRUCT op;
op.hwnd = AfxGetApp()->GetMainWnd()->m_hWnd;
op.pFrom = "\\\\Al\\display\\color\\density\\*";
op.pTo = "C:\\color\\density";
op.wFunc = FO_COPY;
op.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_SILENT | FOF_ALLOWUNDO;
SHFileOperation(&op);
But I get the following error:
Error Copying File or Folder
Cannot copy file: Cannot read from the source file or disk.
|
|
|
|
|
I resolved this issue by using scripting code. I really found KiXtart very useful. KiXtart is an enhanced DOS scripting language with Windows support. Eventually, I combined my Visual C++ 6.0 applications with a couple of KiXtart scripts to perform my network drive remote copy.
IHR
|
|
|
|
|
Took a while
Use in VS2005 a unicode string like L"c:\temp\temp.txt"
As far as I know you cannot read from network source.
|
|
|
|
|
Hi,
I have a requirement of copying files from one folder to another. But my problem is, after copying the file to another folder, I need the destination file which I copied to have the same created date as the source created date. Can you please suggest what to be done for that.
Thanks
|
|
|
|
|
You might need to handle the dates yourself, once the files are in the target directory.
You might need to capture the information prior to the move operation.
For an example of preserving the file date/time and security settings of a file, look at the source for the CMirrorFile class in the MFC source code.
C++/MFC/InstallShield since 1993
|
|
|
|
|
SHFileOperation will return a non-zero if it has failed ;
Where can I find constants for and meanings of the numbers?
Is there a text-conversion function like FormatMessage to convert the number into a string for output/logging?
|
|
|
|
|
I'm also looking for this, lemme know if you find anything!
|
|
|
|
|
GetLastError will answer your question.
Regards,
BB
|
|
|
|
|