Ok this is rough and ready, I'll do my best to explain whats going on, any
questions fire em back ..
It is basically a bit more than a simple copy folder and contents to an
alternative location, this routine is a sync routine so if the file or
folder already exists in the destination it wont be copied again to save
time
If something gets removed from the source it gets removed from the target
etc.
you pass the routine from from and to locations such as
do sync with "c:\testsync\from","c:\testsync\to"
it will first whiz through everything and work out what needs to be done and
store these as actions in a cursor called "sync"
this cursor is then scanned through and the actions performed...
the actions can be seen towards the top of the code. Eg
** simple copy file
CASE ctype="C"
COPY FILE (m.csource) TO (m.ccopy)
** Simple create directory
CASE ctype="D"
MD (m.ccopy)
** update file
CASE ctype="U"
DELETE FILE (m.ccopy)
COPY FILE (m.csource) TO (m.ccopy)
** delete file
CASE ctype="X"
DELETE FILE (m.ccopy)
** delete folder, note agrd is my own implementation of the command prompt
** RD <folder> /S
CASE ctype="Z"
=AGRD (m.ccopy)
RD (m.ccopy)
This really needs some error check to ensure that these operations are
completed successfully, you could maybe even add a success field to the
cursor and create an exceptions report ... for instance if a file is in use
etc etc
Ok here is the main chunk of the code, don't flame me as I said it's rough
and ready and simply serves a purpose this end at the moment.
As an idea if you want to test it on your real data just comment out the
actual actions within the case statement and then review the cursor after to
see what it intended to do
HTH Chris
*** code starts here
LPARAMETERS lcsource,lccopy
LOCAL lcreturn,llreturn
llreturn=.t.
lcreturn=""
IF PARAMETERS()<2
lcreturn="Parameters not specified"
llreturn=.f.
ELSE
IF VARTYPE(lcsource)<>"C" OR VARTYPE(lccopy)<>"C"
lcreturn="Parameters Invalid"
llreturn=.f.
ELSE
IF !DIRECTORY(lcsource) OR !DIRECTORY(lccopy)
lcreturn="Directory Invalid"
llreturn=.f.
ENDIF
ENDIF
ENDIF
IF llreturn
SELECT 0
CREATE CURSOR sync (ctype c(1),csource m(10),ccopy m(10))
=proc_sync(lcsource,lccopy)
SELECT sync
SCAN
SCATTER MEMVAR memo
DO CASE
CASE ctype="C"
COPY FILE (m.csource) TO (m.ccopy)
CASE ctype="D"
MD (m.ccopy)
CASE ctype="U"
DELETE FILE (m.ccopy)
COPY FILE (m.csource) TO (m.ccopy)
CASE ctype="X"
DELETE FILE (m.ccopy)
CASE ctype="Z"
=AGRD (m.ccopy)
RD (m.ccopy)
ENDCASE
ENDSCAN
ENDIF
RETURN lcreturn
***
PROCEDURE agrd
LPARAMETERS lcdir
LOCAL lchome,lndirs,lncounter
LOCAL ARRAY ladeldirs(1)
lchome=SYS(5)+CURDIR()
CD (lcdir)
SET SAFETY Off
DELETE FILE *.*
SET SAFETY on
lndirs=ADIR(ladeldirs,"","D",1)
IF lndirs>0
FOR lncounter = 1 TO ALEN(ladeldirs,1)
IF ladeldirs(lncounter,1)<>"." AND
ladeldirs(lncounter,1)<>".."
=agrd(lcdir+"\"+ladeldirs(lncounter,1))
endif
endfor
ENDIF
IF lndirs>0
FOR lncounter = 1 TO ALEN(ladeldirs,1)
IF ladeldirs(lncounter,1)<>"." AND
ladeldirs(lncounter,1)<>".."
RD (lcdir+"\"+ladeldirs(lncounter,1))
endif
endfor
ENDIF
CD (lchome)
RETURN
***
PROCEDURE proc_sync
LPARAMETERS lcsource,lccopy
LOCAL
llreturn,lnfiles,lndirs,lncopy,lncounter,lchome,lcaction,llcopies,lncopies,l
nresult,lnlocdirs
LOCAL array lafiles(1)
LOCAL array ladirs(1)
LOCAL ARRAY lacopies(1)
LOCAL ARRAY lalocdirs(1)
LOCAL ARRAY lacopy(1)
lcsource=ALLTRIM(lcsource)
lccopy=ALLTRIM(lccopy)
lchome=SYS(5)+CURDIR()
llcopies=.f.
IF DIRECTORY(lccopy)
CD (lccopy)
llcopies=.t.
lncopies=ADIR(lacopies,"*.*","",1)
lnlocdirs=ADIR(lalocdirs,"","D",1)
ENDIF
CD (lcsource)
lnfiles=ADIR(lafiles,"*.*","",1)
lndirs=ADIR(ladirs,"","D",1)
IF lnfiles>0
FOR lncounter = 1 TO ALEN(lafiles,1)
lcaction=""
IF !FILE(lccopy+"\"+lafiles(lncounter,1))
lcaction="C"
ELSE
lncopy=ADIR(lacopy,lccopy+"\"+lafiles(lncounter,1))
IF lncopy=1
DO case
CASE
lafiles(lncounter,3)>lacopy(1,3)
lcaction="U"
CASE
lafiles(lncounter,3)=lacopy(1,3) AND lafiles(lncounter,4)>lacopy(1,4)
lcaction="U"
ENDCASE
ENDIF
ENDIF
IF !EMPTY(lcaction)
INSERT INTO sync (ctype,csource,ccopy);
VALUES
(lcaction,ALLTRIM(lcsource)+"\"+ALLTRIM(lafiles(lncounter,1)),ALLTRIM(lccopy
)+"\"+ALLTRIM(lafiles(lncounter,1)))
ENDIF
ENDFOR
ENDIF
IF lndirs>0
FOR lncounter = 1 TO ALEN(ladirs,1)
IF ladirs(lncounter,1)<>"." AND ladirs(lncounter,1)<>".."
IF !DIRECTORY(lccopy+"\"+ladirs(lncounter,1))
INSERT INTO sync(ctype,csource,ccopy);
VALUES
("D","",ALLTRIM(lccopy)+"\"+ALLTRIM(ladirs(lncounter,1)))
ENDIF
=proc_sync(lcsource+"\"+ladirs(lncounter,1),lccopy+"\"+ladirs(lncounter,1))
ENDIF
ENDFOR
ENDIF
IF llcopies
IF lncopies>0
FOR lncounter = 1 TO ALEN(lacopies,1)
lcaction=""
lnresult=ASCAN(lafiles,lacopies(lncounter,1),-1,-1,1,1)
IF lnresult=0
lcaction="X"
ENDIF
IF !EMPTY(lcaction)
INSERT INTO sync (ctype,csource,ccopy);
VALUES
(lcaction,"",ALLTRIM(lccopy)+"\"+ALLTRIM(lacopies(lncounter,1)))
ENDIF
ENDFOR
ENDIF
ENDIF
IF llcopies
IF lnlocdirs>0
FOR lncounter = 1 TO ALEN(lalocdirs,1)
lcaction=""
lnresult=ASCAN(ladirs,lalocdirs(lncounter,1),-1,-1,1,1)
IF lnresult=0
lcaction="Z"
ENDIF
IF !EMPTY(lcaction)
INSERT INTO sync (ctype,csource,ccopy);
VALUES
(lcaction,"",ALLTRIM(lccopy)+"\"+ALLTRIM(lalocdirs(lncounter,1)))
ENDIF
endfor
endif
endif
CD (lchome)
RETURN
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Nick
Sent: 01 September 2006 14:53
To: [EMAIL PROTECTED]
Subject: RE: Move directories
Yes please Chris, I definitely am looking for a fox solution. The use of
external APIs is only to do the bits fox can't do itself.
If you have a routine which solves this it would be very helpful.
Cheers,
Nick
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.