|
-
May 23rd, 2004, 03:44 AM
#1
Copy files
Hi,
I am writing a C console application in .NET 2003 IDE.
Is there any function to copy file(s)
I have included "direct.h" header file but it does not seem to support copying file.
I am left with the only system() call option which i guess does not satisfy me performance needs
Thanks in advance
-
May 23rd, 2004, 04:07 AM
#2
-
May 23rd, 2004, 04:10 AM
#3
Is the target system still the Windows environment? In this case, you can use the API functions 'CopyFile()'/'CopyFileEx()'...
-
May 23rd, 2004, 03:12 PM
#4
Thanks.
Windows should be fine.
Does the moving of the thread imply no non-visual C++ support to copy files ?
-
May 23rd, 2004, 04:58 PM
#5
Well...yes and no. The movement was done due to the fact that you are using Visual C++ .NET.
However, there is indeed no standard function available...if you want to do it platform-independent you would have to implement it on your own...
-
May 23rd, 2004, 08:30 PM
#6
write the function it's easy!!
-
May 23rd, 2004, 08:43 PM
#7
Re: Copy files
Originally posted by nsh123
Hi,
I am writing a C console application in .NET 2003 IDE.
Is there any function to copy file(s)
I have included "direct.h" header file but it does not seem to support copying file.
I am left with the only system() call option which i guess does not satisfy me performance needs
Thanks in advance
Then implement it yourself. Use fopen(), fread(), fwrite(), fclose(). Those are the C file I/O functions, and they are contained in <stdio.h>.
Regards,
Paul McKenzie
-
May 24th, 2004, 01:52 AM
#8
Originally posted by Loosejeans
write the function it's easy!!
I know its easy.
I wanted to make sure i do not reinvent the wheel. Especially when it not going to do any good in performance.
-
May 27th, 2004, 03:25 AM
#9
Originally posted by nsh123
I know its easy.
No, it certainly is not easy!
It is even rather difficult to copy a file correctly on NTFS.
Some points of difficulty:
- Copying the security attributes of the file.
- Encrypting destination file if source file is encrypted. But which encryption keys should be used: the keys used to encrypt the source file or the default keys of the user? What if the source file is encrypted, but the destination folder has encryption disabled?
- Compressing destination file if source file is compressed.
- Copying alternate streams of the file to the destination file.
- What about sparse files? If you just use fopen/fwrite..., you will expand the sparse file and destination file will not be sparse anymore.
Best solution to copy files on NTFS is SHFileOperation.
-
May 27th, 2004, 06:40 AM
#10
Originally posted by Marc G
Best solution to copy files on NTFS is SHFileOperation.
Which is rather a subjective opinion I might add...
-
May 27th, 2004, 08:18 AM
#11
Originally posted by Andreas Masur
Which is rather a subjective opinion I might add...
Ok ... you would use CopyFile(Ex)?
If you do, all alternate streams in the file will silently be ignored. That can't be good, is it?
-
September 5th, 2005, 10:43 AM
#12
Re: Copy files
 Originally Posted by Marc G
Ok ... you would use CopyFile(Ex)?
If you do, all alternate streams in the file will silently be ignored. That can't be good, is it?
Is that so? I have read an alternate streams howto
http://www.flexhex.com/support/resou...-streams.phtml
and it says CopyFile does copy alternate streams. Is CopyFile really reliable or must I implement it myself?
-
September 5th, 2005, 12:06 PM
#13
Re: Copy files
You do know that this thread is more than a year old?
Anyway, the saves way to copy files is to use SHFileOperation.
-
September 6th, 2005, 06:43 AM
#14
Re: Copy files
 Originally Posted by Marc G
You do know that this thread is more than a year old?
Yes I know. What's wrong with it? Alternate streams are still with us, aren't they?
 Originally Posted by Marc G
Anyway, the saves way to copy files is to use SHFileOperation.
Well I don't think SHFileOperation is the universal choice. It is kind of too high level with all those confirmation dialogs and progress bars and whatsit.
Just FYI - I decided to investigate myself after all, and found that CopyFile does copy alternate streams, and in general works exactly as that article descibed. So there is no need to fiddle with SHFileOperation, CopyFile is quite safe.
-
September 6th, 2005, 09:12 AM
#15
Re: Copy files
 Originally Posted by freim
Well I don't think SHFileOperation is the universal choice. It is kind of too high level with all those confirmation dialogs and progress bars and whatsit.
it can be run also in silent mode, if you will specify the correct params, and no dialogs will appear. 
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|