Board index » delphi » Copying files and dirs
Martin R.
![]() Delphi Developer |
Fri, 05 Jan 2001 03:00:00 GMT
|
Martin R.
![]() Delphi Developer |
Fri, 05 Jan 2001 03:00:00 GMT
Copying files and dirs
I'm a rather beginning Delphi programmer, but I must say Delphi's
documentation is not very helpful at that issue. Is it really necessary to write own procedures for copying a whole Is there a windows counterpart for old pascal's: Exec('c:\command.com', '/c xcopy /q /e /r /y c:\adir d:\adir'); ? Please help if you can... |
Jeremy Collin
![]() Delphi Developer |
Fri, 05 Jan 2001 03:00:00 GMT
Re:Copying files and dirsQuote>Is it really necessary to write own procedures for copying a whole you like moving, copying and deleting files and directories, but sometimes you'll need to resort to FindFirst/FindNext. Quote>Is there a windows counterpart for old pascal's: ShellExecute(Handle, nil, 'c:\command.com', But you shouldn't hard-code "command.com" or it won't work under (return address not altered 'coz I get spammed *whatever* I do!) |
Jacques Micho
![]() Delphi Developer |
Fri, 05 Jan 2001 03:00:00 GMT
Re:Copying files and dirs
QuoteMartin R. wrote: Try the procedure copyfile() in the unit fmxutils. J.Michot |
CEHJohns
![]() Delphi Developer |
Fri, 05 Jan 2001 03:00:00 GMT
Re:Copying files and dirsI agree, there should be a better way of doing this - but you can use the principle of your code with the ShellExcute function (include ShellAPI in Uses clause) Charles Johnson |
Ken Whit
![]() Delphi Developer |
Fri, 05 Jan 2001 03:00:00 GMT
Re:Copying files and dirsMartin, If you're using Delphi 2, 3, or 4, you can use SHFileOperation, Ken Clipper Functions for Delphi QuoteMartin R. wrote: |
Martin R
![]() Delphi Developer |
Sat, 06 Jan 2001 03:00:00 GMT
Re:Copying files and dirsI have solved my problems, partially by using Delphi's own functions, partially by using functions from the Windows unit and partially by FindFirst, FindNext, FindClose... Using ShellExecute didn't satisfy me because I had the feeling, that |
Andreas Kyriaco
![]() Delphi Developer |
Sat, 06 Jan 2001 03:00:00 GMT
Re:Copying files and dirsThe message <35B3F66D.86A49...@westelcom.com> from Ken White <kwh...@westelcom.com> contains these words: Quote> Martin, I saw your suggestion above so I thought I'd try it. "Error Copying File The Win32 help implies but does not explicitly state that the function Can anybody tell me what I am doing wrong? -- Andreas Here is my code var implementation {$R *.DFM} {============ SaveDialog1.Filename:=ExtractFileName(OpenDialog1.FileName); {fill in the TSHFileOPstruct} {make the API call} end. |
Martin Harve
![]() Delphi Developer |
Sun, 07 Jan 2001 03:00:00 GMT
Re:Copying files and dirsQuoteMartin R. wrote: like this, so you don't have to use ShellExecute. In addition, the app waits for completion (since, currently, Win32 file IO is synchronous, although I think some message based functions have recently been, or will be added) Incidentally, ShellExecute is obsolete. You should use CreateProcess. ShellExecute and CreateProcess operate concurrently. If you want to wait Quote> The worst thing is, that if you really want to code a clean 'CopyDir' containing the files you know about that haven't currently been copied. Just go through the list, trating dirs and files appropriately, and then repeat until there's nothing left in the list. Have you thought about cases where the destination is a subdir of the MH. |
Ken Whit
![]() Delphi Developer |
Tue, 09 Jan 2001 03:00:00 GMT
Re:Copying files and dirsAndreas, Surround your filename with double quotes... For example, if you sFileName := '"c:\program files\borland\delphi 3\images\myfile.avi"'; When you're dealing with a record (structure, in C-speak), you FillChar(FileOpStruct, SizeOf(TSHFileOpStruct), 0); Also, the Win32 API help file has an error in it... You should FileOpStruct.pFrom:=Pchar(OpenDialog1.FileName) + #0; This should fix the problem with SHFileOperation... As far as the Windows error goes, try using this: ShowMessage(SysErrorMessage(GetLastError)); Ken Clipper Functions for Delphi QuoteAndreas Kyriacou wrote: |
Andreas Kyriaco
![]() Delphi Developer |
Sun, 14 Jan 2001 03:00:00 GMT
Re:Copying files and dirsThe message <35B90F17.F81C4...@westelcom.com> from Ken White <kwh...@westelcom.com> contains these words: Quote> Andreas, Many thanks for your suggestions, they were helpful in cracking Here is what I have discovered. 1) The windows error number. 2)The destination string that FileOpStruct.pTo points to is a directory. 3)It stops working if you include a #0 on the end of the destination FileOpStruct.pTo:=Pchar('F:\ADIRECTORY\'+#0), but it won't work without a #0 at the end of the source string. FileOpStruct.pFrom:=Pchar('D:\Mylongfile.avi'+#0) 4)Surrounding either the source or destination path in quotes also I have attatched a functioning copy of my code at the bottom of the -- Andreas Here is my Working Code var implementation {$R *.DFM} {============ {fill in the TSHFileOPstruct} {make the API call} |