Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copyfile, copydir? 1

Status
Not open for further replies.

redzombi19

Programmer
Jun 2, 2002
35
US
hi guys i was wondering if there was a windows api call or foxpro command that will copy a directory, i know the api call movefile will move a complete directory but it seems that copyfile only works on acutual files not directory's.
thanks
 
ok when i try that i get :
OLE error code bla,bla,bla: Unknown COM status code.

here is a sample of the code i used for moving directories:

Declare Integer MoveFile IN WIN32API String @cFrom, String @cTo
MoveFile("c:\startdir","c:\enddir")
 
If you're trying to move a folder, you need to use MoveFolder, not MoveFile:

ofs.MoveFolder("C:\data", "c:\newdata")
Moves, or rather renames the folder 'data' to 'newdata'.

ofs.MoveFolder("C:\data", "c:\newdata\today")
Moves the folder named 'data' and places it as a new folder under 'newdata' in the tree.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
thanks for you help DSummZZZ, let me explain mabey a little more clearly...
the above code you supplied gives me the same error every time, mabey its because i am doing something wrong, but the sample code i geve you is a windows api call that does in fact move directories and all of its sub folders and files it is called movefile...go figure. try pasting it into the click on a button to experament.
i am now trying to not move but copy a directory and all of its subfolders and files, if you can think of somethinig i might be doing wrong in you code please let me know.
thanks a lot.
 
ok, im an idiot i was miss-spelling a word in the original part of my code that you supllied :)
corrected it and it worked like a charm!
thank you verry much !!!!!
 
ok but now i have one small problem this code will only work on machines with windows scripting installed on them, which not all do.
is there not a api call to handle this ?
 
Sorry, I didn't see any API calls for copying or moving an entire directory. I have seen some posts in this form for copying files using VFP code, which traverse trees and so on, but the only other thing I have found is using scripting.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
Forgot one this, SHFileOperation displays a window dialog with progress bar & animation (same with Windows Explorer)

-- AirCon --
 
Do you need it to recursively copy subdirectories?

If not, this should work:

COPY FILE \Your\Path\*.* TO \Dest\Path
Or some variant of that (I don't remember if the trailing "\" is needed in the Destination or not...)
 
Wgcs,
I used "copy file path1 to path2" but when the lenght of path1 is bigger the copy doesn't work.
 
Machele

It works, just don't put "\" for the destination, as Wgcs already mentioned
I don't remember if the trailing "\" is needed in the Destination or not

try this.

cFile1 = 'D:\My Program\VFP7\Samples\*.*'
cFile2 = 'C:\Temp'
Copy file (cFile1) to (cFile2)


-- AirCon --
 
i put
cFile1 = 'c:\Program files\VFP7\marius\*.*'
cFile2 = 'C:\Temp'
Copy file (cFile1) to (cFile2)
and doesn't work.
If i substitute "Program files" with another folder "max" it's work
 
Machele

I'm not sure what is happening. I tried with various path length under W2K & WinME, always work.

Well, this maybe a stupid question :) but are you sure that the directory exist?


-- AirCon --
 
it's only idea, but what about the spaces in the names of folders ?

Monika from Warszawa (Poland)
(monikai@yahoo.com)
 
Alternatives to Dave's solution:
Code:
cFile1 = "C:\PROGRAM FILES\MICROSOFT VISUAL FOXPRO 7\Dave\*.*"
cFile2 = 'C:\Temp\*.*'
Copy file "&cFile1" to "&cFile2"

*or 

Copy file (cFile1) to (cFile2)
Rick

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top