Hello,
I would like to make a copy function, like xcopy but in c++.I wouldn't use xcopy in my c++ file, because I don't have enough error catching.
I would like to copy the whole directory structure from source to destination, but if the file or directory exists in the destination, it may not be copied again.
I wrote this code. But it doesn't work. Can somebody help me please? - SHFILEOPSTRUCT fileop;
-
fileop.hwnd = NULL;
-
fileop.wFunc = FO_COPY;
-
fileop.pFrom = "C:\\a\\*.*\0"; // additional null needed
-
fileop.pTo = "C:\\b\\\0"; // additional null needed
-
fileop.fFlags = FOF_NOCONFIRMATION|FOF_NOCONFIRMMKDIR |FOF_RENAMEONCOLLISION;
-
-
if (!SHFileOperation(&fileop) == NULL)
-
{
-
printf("copy failed");
-
getchar();
-
}
8 2772 Banfa 9,065
Recognized Expert Moderator Expert
In what way does it not work?
Nope, Because if I coppied the directory "foo" (c:\a\foo) to (c:\b\). I get c:\'\foo. Ok, that's correct, but if I copied c:\a\foo again to c:\b\. I get this:
-c:\
-b\
-foo\
-copy of foo\
And that's not wat I'm want, I want this, if I coppied the directory again:
-c:\
-b\
-foo\
If I change a file in c:\a\foo and I copied it to c:\b en foo and the file does exists in this directory, I want that the file becomes overwrite.
So, Directories may not overwrite and files must be overwrite.
I hope I make myself clear enough.
Banfa 9,065
Recognized Expert Moderator Expert
The FOF_RENAMEONCOLLISION flag you are using specifically tells the function to rename (add "Copy of") if the destination already exists.
Yes I know,
But the directories may not get "Copy of" but files with the same name must get "Copy of"
How do I do that?
Banfa 9,065
Recognized Expert Moderator Expert
Instead of calling a shell function you do the work yourself making use of the File management Functions in WIN32.
With the use of the FOF_NORECURSION flag you could probably still use SHFileOperation to do the file copying while handling the directories yourself.
Do you have any tips or an example, because that's the reason why I'm asking.
Banfa 9,065
Recognized Expert Moderator Expert
Not really, I have done this sort of thing in the past but not recently, I think you could use FindFirstEx plus related functions to traverse your directory tree to copy creating directories in the destination as required and copying the files.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mike |
last post by:
I want to be able to copy a directory of files (all .HTM files) from a
network drive to a local drive on the machine c:\HTMFiles , How can i do
that?
I tried File.Copy(source, dest) but i need...
|
by: Wayne Wengert |
last post by:
I am using VSNET 2003 to build an ASP.NET/VB set of pages. There are
currently about a dozen aspx pages. When I make even a minor change to one
page I currently rebuild the solution, copy the...
|
by: Johnny |
last post by:
Hi,
I have created an ASP.NET application (let's call it FooBar) with VS.NET on
my local machine, residing in http://localhost/FooBar. Deploying it to
another folder on my machine works well...
|
by: Steve Franks |
last post by:
The Copy Web tool provided with VS.NET 2005 is very convenient. However
every once in a while it seems to think the files on the remote server have
changed, which they have not. Then when I use...
|
by: DraguVaso |
last post by:
Hi,
I'm looking for a way to Copy and Paste Files to the clipboard.
I found a lot of articles to copy pieces of text and bitmaps etc, but nog
whole files.
Whay I need is like you have in...
| |
by: luis molina Micasoft |
last post by:
it seems that when i do file.copy the svchost.exe is hanged, i mean if i make
40 threads of file.copy , 40 copys of files at same time the system is going
down and stop responding, this is when i'm...
|
by: dkmarni |
last post by:
Hi,
I am trying to do this perl script, but not able to complete it successfully.
Here is the description what the script has to do..
Accept two and only two command line arguments. Again,...
|
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= |
last post by:
Using .NET 2.0 is it more efficient to copy files to a single folder versus
spreading them across multiple folders.
For instance if we have 100,000 files to be copied,
Do we copy all of them to...
|
by: =?Utf-8?B?UmFkZW5rb19aZWM=?= |
last post by:
I am using standard File.Copy(source,dest,true) method in C# and I have
problem with copying large number of files.
Here is my code:
foreach (FileInfo file in files)
{...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |