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

copy file 2

Status
Not open for further replies.

white605

Technical User
Jan 20, 2003
394
US
Copy File c:\test\*.* to d:\backup\*.*
will copy all files in the test directory but does not get the subdirectories. Is there an eazy way to get them all?
wjwjr
 
I've always liked this question... so this time I thought I would try and write some code to handle this. I create an array using a recursive function that will contain all of the files (full path) within the specified directory (including all sub directories). Cut-N-Paste the code below into a prg file and run it from within VFP. It's easiest to see the array from the debugger.

Dimension aryFiles(1)
=GetAllFiles(GETDIR(), @aryFiles)
SET STEP ON

FUNCTION GetAllFiles(cDirectory, aryParam)
*!* EXTERNAL ARRAY aryAllFiles
LOCAL ARRAY aryTemp(1,5)
LOCAL nCount, nMax, nLen, cFile
SET DEFAULT TO (cDirectory)
=ADIR(aryTemp, "*.*","AHRSD",1)
nMax = ALEN(aryTemp,1)
FOR nCount = 1 TO nMax
cFile = ALLTRIM(aryTemp(nCount,1))
IF !(cFile == ".") AND !(cFile == "..")
IF "D" $ aryTemp(nCount,5)

=GetAllFiles(ADDBS(cDirectory + cFile), @aryParam)

ELSE

nLen = ALEN(aryParam)
IF !EMPTY(aryParam(nLen))
DIMENSION aryParam(nLen + 1)
nLen = nLen + 1
ENDIF
aryParam(nLen) = cDirectory + cFile

ENDIF
ENDIF
ENDFOR
ENDFUNC


Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
SLighthaze,

Yet another way..

See my FAQ
A cursor to collect all files in a specific directory
faq184-3102
This can be made to collect all recursive also...

=doDirFiles(cmyDir,.t.) for recursive
=doDirFiles(cmyDir,.f.) for root files only


we can make that as a function..
*********************************************************
** Author : Ramani (Subramanian.G)
** FoxAcc Software / Winners Software
** ramani_g@yahoo.com
** Type : Freeware with reservation to Copyrights
** Warranty : Nothing implied or explicit
** Last modified : 31 January, 2003
*********************************************************
** The following uses Filer.DLL and
** extracts all files in a directory as a cursor.
*********************************************************
FUNCTION doDirFiles
PARAMETERS tcDir, tlRecurse

IF VARTYPE(tcDir) # "C"
tcDir = "C:\"
ENDIF
IF VARTYPE(tlRecurse) = "U"
tlRecurse = .t.
ENDIF

CREATE CURSOR filename (cfilename c(128))
omyfiler = CREATEOBJECT('Filer.FileUtil')
omyfiler.searchpath = ADDBS(ALLT(tcDir))

IF tlRecurse
omyfiler.subfolder = 1 && Recurse
ELSE
omyfiler.subfolder = 0 && Only roo directory
ENDIF
oMyFiler.SortBy = 0
omyfiler.FIND(0)
LOCAL ncount
ncount = 1
FOR nfilecount = 1 TO omyfiler.FILES.COUNT
IF omyfiler.FILES.ITEM(nfilecount).NAME = "." OR ;
omyfiler.FILES.ITEM(nfilecount).NAME = ".."
LOOP
ENDIF
APPEND BLANK
REPLACE cfilename ;
WITH UPPER(omyfiler.FILES.ITEM(nfilecount).PATH)+ ;
UPPER(omyfiler.FILES.ITEM(nfilecount).NAME)
ENDFOR
BROW
**********************************************************

:)

ramani :)
(Subramanian.G)
 
Hi,

May be we have provided only a solution which could lead you to achieve what you want. But the follwoing is a simpler code and a much easier alternative.

lcBackUp = [XCOPY "]+lcSource+[" "]+[lcDestination]+[" /s]
loShell = CREATEOBJECT("wscript.shell")
lnSuccess = loShell.Run(lcBackUp,1,.t.)

You can suitably change lcSource and lcDestination and get your objective done. Include the path also in these variables.

:)

ramani :)
(Subramanian.G)
 
Also, you could do this:

oFilesys=CreateObject("Scripting.FileSystemObject")
oFilesys.CopyFolder('C:\MyFolder','C:\MyCopy')

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Thanks a lot - Surely with the above code noone should ever loose any data!
stars for the both of you
wjwjr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top