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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Folder/directory and contents 1

Status
Not open for further replies.

volfreak

Programmer
Nov 6, 2000
42
US
I'm sure I'm not the 1st to encounter this, but I'd like to be able to copy a folder from one location to another and have all its contents (which could include nested folders) in VFP6.

I know the COPY FILE function exists, but I don't want to have to figure out does this folder have other folders and do they have folders, etc. and then copy each file from each folder. VB has a COPYFOLDER function (I think is the name of it) which will do what I want. I thought maybe the WIN32API would have one but I couldn't find it.

Does anyone know of a system call or an existing utility/code that I can access/use in VFP 6 which would provide this feature?

Thanks in advance for any/all help.

Cheers ;-)
 
HI
Why not use the command..

mySource = "E:\myFolder"
myDest = "C:\myFolder"

IF ! DIRECTORY(myDest)
! MD &myDest
ENDIF
! xcopy &mySource &myDest /Y/S

YOu may use /N option if you dont want display.

Hope this helps :) ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Watch out for long filenames though! (enclose them in quotes)
And long instructions are generally a problem with the
run command (!) in VFP.

For best results, you would probably be best creating a batch file (either using a 'set alte to' or a StrToFile() command) and then running the batch file. This also gives you the chance to debug later by editing the contents of the batch file.

VFP has a mkdir command MD which eliminates the need to run !MD as well.

HTH
Griff
[smile]

 
Thanks for the tips. I've got the xcopy working but, yes, it does have problems with long folder names. Long filenames within a folder seem okay.

It just amazes me that there is no function that one can call in the MSVFP development environment that would do this. To have to resort to batch files and the like is just pathetic.

Eh, but what does one expect when even the OS can't determine before it copies files if there's enough room on the destination disk before it processes the commands.

Thanks again and cheers.
 
I've recently stumbled across the "Scripting" object in Windows. Among its many objects are "Copy Folder", "Delete Folder", and "Move Folder". It sounds like this may just do the trick. If you've got VFP 7 with Intellisense you'll see all of the other things that you can do with files.

Type this in your VFP command Window:

objFileSystem = CreateObject("Scripting.FileSystemObject")

Steve
 
Thanks for reminding me about that Steve. I used this a little over a year ago on one occasion. I did run into problems with the EXE running on Win98 boxes - they had to have some additional libs installed/registered and even then, there was inconsistent results.

But this will be running on NT4 or 2K so everything should be there. I'll look @ tomorrow.

Thanks again.
 
Alright, I dug out my old code and now trying it, I get an error that I can't seem to identify why I'm getting it nor what problem it indicates.

The FileSystemObject is created.

When I issue the CopyFolder method, I get:

OLE Error 0x800a004c. Unknown COM Status Code.

Searching the MS website for this has proven fruitless.

Any thoughts?

Thanks,
 
Of course, as soon as I post this, I solve it.

Thanks again for all the tips.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top