|
I'm missing the TCHAR type (we use Unicode for everything) and localizable error messages. How would the utils work with a non-English OS?
|
|
|
|
|
excellent wrapper, nice description.
|
|
|
|
|
|
Hi
i am working on VC7,and using CFileOperation::Copy() function.
Problem is i am unable to find the root cause of the exception raised in Copy() function.
Normal Try,Catch are unable to get the Error Message.
With the help of GetErrorString(), i am getting "Unspecified Error" which is not helpful.
Please provide me with a function that can return the exact\approximate error type from Copy() function.
Thanks in advance,
Anandi
|
|
|
|
|
your code can't copy subFolder?
|
|
|
|
|
Windows could not read one of drives, I saved all the files using this program
great job
|
|
|
|
|
|
To delete a directory, you use the CFileFind class and FindFile method like this :
<br />
sPath += "*.*";<br />
BOOL bRes = ff.FindFile(sPath); <br />
But if sPath is empty you will delete all files on your hard drive !!!
I didn't test it, perhaps it works well but if someone modify your code, I just wanted to inform him that it can be dangerous to manipulate this !!!
Regards
Sebastien
|
|
|
|
|
can you give me an example of your code, but without using MFC ???
Thanx.
|
|
|
|
|
Hi,
I was wondering if there is a way of copying files to a server using an IP address. I can easily copy/move/etc files to the servers in my network using something like this \\MyServer\RAID...
But I need to copy files to a remote server using the IP address. Let me know if there is a way of doing that.
Thanks!
|
|
|
|
|
I tried out this Code Project class before switching to Boost's FileSystem library. The Boost library provides similar functionality, but has many advantages. For instance, the Boost library is:
* Widely tested, and in use by thousands of programmers
* Exceptionally well designed
* Platform independent
* Not buggy
* MFC and stdafx.h free
The Boost FileSystem library is at http://www.boost.org/libs/filesystem/doc/index.htm
The main Boost page is at http://www.boost.org/
I would highly recommend the Boost library.
-Joe
|
|
|
|
|
boost is too big!!! the code is too complex, so you can hardly change the code, i don't want to use it ,though i read it.
|
|
|
|
|
This code fragment appears frequently:
<br />
catch(CFExeption* e)<br />
{<br />
m_sError = e->GetErrorText();<br />
m_dwError = e->GetErrorCode();<br />
delete e;<br />
if (m_dwError == 0) bRes = true;<br />
bRes = false;<br />
}<br />
surely this will always set bRes to false?
You could just use "bRes = m_dwError == 0;"
Further investigation shows that m_dwError is set to 0 even when errors occur, for instance if you call Copy with a non-existant destination, the string is set but the error is zero so the caller thinks the function worked. Not good.
|
|
|
|
|
Yes, it's a bug.
In the near future i'm planning update this article.
New version will not use MFC. All known bugs will be fixed.
Also i taking in response to the wishes.
<fess>
|
|
|
|
|
Hello,
When do you expect to have the new modified code available?
John
|
|
|
|
|
Just a little remark : some little modifications would have allowed to run your code with _UNICODE
Guillaume.
|
|
|
|
|
I echo that!
It's so easy to do, yet no one does it....
It bugs me to no end that people use TCHAR and LPCTSTR without knowing why. If you're gonna use these things, then at least compile it with UNICODE enabled.
One additional note, making file code that is not UNICODE-able is plain old lame. The file system does allow people to make filenames and folders with unicode characters (not supported in ANSI).
UNICODE is a must -- these days!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc.</A>
|
|
|
|
|
hey ,,very usefull code..
but am new ,,i mean very new , and all i need is ,code that copy the corract file to other dirctory e,g "C:\pic\user.exe" to "C:\windows\system32\user.exe"...
now i have those function :
char * GetWorkingDirectory()
{
//Function to get directory of program
//------------------------------------
//Variables
char * szFileName = new char[MAX_PATH];
char temp;
HINSTANCE hInstance = GetModuleHandle(NULL); //Get handle
GetModuleFileName(hInstance, szFileName, MAX_PATH); //Get path to program
//Initiate X with length of path
int x = strlen(szFileName);
bool ExitLoop = 0; //Set to 0
//Loop until brace (\) and terminate path there.
do
{
//Use tempchar
temp = szFileName[x];
if( temp == 92) //Check for brace (\)
{
szFileName[x + 1] = 0;
ExitLoop = 1;
}
x--; // Countdown
//If zero, then return NULL, which results in error
if(x == 0)
{
return NULL;
}
}
while(!ExitLoop); //While exitloop not set
return szFileName; //Return pointer to working directory
}
// and this part from uer handy code but i play with it a littel :P
void CFileOperation::DoFileCopy(CString sSourceFile, CString sDestFile, bool bDelteAfterCopy)
{
BOOL bOvrwriteFails = FALSE;
sSourceFile = "C:\pic\user.exe";
sDestFile = "C:\windows\system32\user.exe" ;
if (!m_bOverwriteMode)
{
while (IsFileExist(sDestFile))
{
sDestFile = ChangeFileName(sDestFile);
}
bOvrwriteFails = TRUE;
}
if (!CopyFile(sSourceFile, sDestFile, bOvrwriteFails)) throw new CFExeption(GetLastError());
if (bDelteAfterCopy)
{
DoDelete(sSourceFile);
}
}
so ,,how can i creat from those 2 functions what i need? ,or on other word how can i make them wrok togther
i wish someone can help me with that ,,
paece.
|
|
|
|
|
If you need copy "C:\pic\user.exe" to "C:\windows\system32\user.exe" just do:
СFileOperation fop;
fop.SetOverwriteMode(true);
if (!fop.Copy("C:\\pic\\user.exe", "C:\\windows\\system32"))
{
// if copy failed, get error code or error string
DWORD dwError = fop.GetErrorCode();
CString sError = fop.GetErrorString();
}
But if you need to copy only one file you can use system function:
if (!CopyFile("C:\\pic\\user.exe", "C:\\windows\\system32\\user.exe", FALSE))
{
// if copy failed, get error code
DWORD dwError = GetLastError();
}
<fess>
|
|
|
|
|
problem happens when there are several folders and files in source folder. Only files and one of the folder are copied into the destination folder, which looks like c:\abc-def. Any suggestion?
|
|
|
|
|
i have check your situation and it's ok.
please describe your problem in more details....
<fess>
|
|
|
|
|
In the CFileOperation::Copy(CString sSource, CString sDest) function with having set SetOverwriteMode(true) before, a necessary precondition in this code is that sDest already exists, because of many calls to CheckPath() in this code, which will return PATH_NOT_FOUND if the file or directory does not already exist.
So you already first have to create an empty dummy file or directory sDest before successfully using CFileOperation::Copy(). This is a bit unusual usage, compared to e.g. what is possible to do in a MS-DOS command window, isn't it ??
|
|
|
|
|
Destination path must exist.
if you try copy "c:\test.dat" to "c:\dir", "c:\dir" must exist.
if in "c:\dir" file "test.dat" already exist and OverwirteMode is set it will be replaced with new file.
Functionality is similar to the files operations API.
<fess>
|
|
|
|
|
Yes, you are right.
But, in MS-DOS window, however, the following statement also works correctly:
COPY C:\test.dat C:\dir\test.dat
if C:\dir already exists and if C:\dir\test.dat does exist or not.
I would have expected a similar functionality in your CFileOperation::Copy() method (not only that something like "COPY C:\test.dat C:\dir\" would work ...)
|
|
|
|
|
I love your class but did you try to use CopyFileEx ? When I try to use it I have ' error C2065: 'CopyFileEx' : undeclared identifier'. Even adding
#define _WIN32_WINNT 0x0500 before
#include <windows.h>
doesn't work. According to msdn it should have
Do you have any idea what's wrong? I tried to find a solution everywhere, but that's all I've found.
______
Zombie.
|
|
|
|