Discussion:
Move directories
(too old to reply)
Nick Causton
2006-08-31 16:48:53 UTC
Permalink
Any suggestions how I can move a directory (including any subdirectories and
files) from one drive to another?

So far I have tried:
MoveFile Win32API - will not move across drives, also does not like UNC file
paths
WScript.Shell - Fails with OLE error code 0x800a0046/004c/003a if directory
has multiple subdirectories
XCOPY - RUN command fails because command length > 256 characters (very long
directory/file names)

Nick
s***@adribbers.com
2006-08-31 16:59:27 UTC
Permalink
Post by Nick Causton
Any suggestions how I can move a directory (including any subdirectories and
files) from one drive to another?
MoveFile Win32API - will not move across drives, also does not like UNC file
paths
WScript.Shell - Fails with OLE error code 0x800a0046/004c/003a if directory
has multiple subdirectories
XCOPY - RUN command fails because command length > 256 characters (very long
directory/file names)
why not xcopy /E to include all the empty folders as well as all folders
with files?

HTH
Jim Winter
2006-08-31 17:09:19 UTC
Permalink
Post by Nick Causton
Any suggestions how I can move a directory (including any subdirectories and
files) from one drive to another?
MoveFile Win32API - will not move across drives, also does not like UNC file
paths
WScript.Shell - Fails with OLE error code 0x800a0046/004c/003a if directory
has multiple subdirectories
XCOPY - RUN command fails because command length > 256 characters (very long
directory/file names)
Nick
Nick,

Just open up 2 copies of Windows Explorer, shift + left click on the
directory you want to move, drag it to the second copy of Explorer and drop
it on the new drive.

Regards,
Jim
Chet Gardiner
2006-08-31 19:06:31 UTC
Permalink
I think he's trying to do it in a VFP program...?
Post by Jim Winter
Post by Nick Causton
Any suggestions how I can move a directory (including any subdirectories and
files) from one drive to another?
MoveFile Win32API - will not move across drives, also does not like UNC file
paths
WScript.Shell - Fails with OLE error code 0x800a0046/004c/003a if directory
has multiple subdirectories
XCOPY - RUN command fails because command length > 256 characters (very long
directory/file names)
Nick
Nick,
Just open up 2 copies of Windows Explorer, shift + left click on the
directory you want to move, drag it to the second copy of Explorer and drop
it on the new drive.
Regards,
Jim
[excessive quoting removed by server]
Nick
2006-08-31 20:10:15 UTC
Permalink
Post by Chet Gardiner
I think he's trying to do it in a VFP program...?
Exactly, there are a few thousand directories, moving each one manually
might take some time ;)
Post by Chet Gardiner
why not xcopy /E to include all the empty folders as well as all folders
with files?
Because we don't want the whole lot moved only a selection of them; those
that have a certain string (year) in their name.
Post by Chet Gardiner
Fox's rename will move files across drives, but you'll have to handle
the directory structures with adir(<AA>,<path+*.*>,"D") & md. (Currently
working on a fox version of xcopy).
Fox version of XCopy would be _extremely_ interesting.


Rgds,
Nick
Richard Kaye
2006-08-31 20:30:44 UTC
Permalink
Have you tried splitting the process to first copy using the CopyFile
API and then deleting the source folders after confirming a successful copy?
Post by Nick
Post by Chet Gardiner
I think he's trying to do it in a VFP program...?
Exactly, there are a few thousand directories, moving each one manually
might take some time ;)
--
Richard Kaye
Artfact/RFC Systems
Voice: 617.219.1038
Fax: 617.219.1001

For the fastest response time, please send your support
queries to:

Technical Support - ***@rfcsystems.com
Australian Support - ***@rfcsystems.com
Internet Support - ***@rfcsystems.com
All Other Requests - ***@rfcsystems.com

---------------------------------------------------------
This message has been checked for viruses before sending.
---------------------------------------------------------
Nick
2006-09-01 10:43:44 UTC
Permalink
Post by Richard Kaye
Have you tried splitting the process to first copy using the CopyFile
API and then deleting the source folders after confirming a successful copy?
Copy file only does individual files not whole directories with subfiles and
subdirectories.

Nick
Sietse Wijnker
2006-09-01 01:12:29 UTC
Permalink
Here's something I cooked up while waiting for a convert-program running:

It uses the SHFileOperation API which is also used when dragging files from
one folder to another in winexplorer.

Regards,
Sietse Wijnker

***********************************************************
*- Defines for the SHFILEOPSTRUCT.wFunc
#Define FO_MOVE 0x0001
#Define FO_COPY 0x0002
#Define FO_DELETE 0x0003
#Define FO_RENAME 0x0004

*- Defines for the SHFILEOPSTRUCT.fFlags
#DEFINE FOF_ALLOWUNDO 0x0040
#DEFINE FOF_CONFIRMMOUSE 0x0002
#DEFINE FOF_FILESONLY 0x0080
#DEFINE FOF_MULTIDESTFILES 0x0001
#DEFINE FOF_NOCONFIRMATION 0x0010
#DEFINE FOF_NOCONFIRMMKDIR 0x0200
#DEFINE FOF_NOCOPYSECURITYATTRIBS 0x0800
#DEFINE FOF_NOERRORUI 0x0400
#DEFINE FOF_RENAMEONCOLLISION 0x0008
#DEFINE FOF_SIMPLEPROGRESS 0x0100

*- Declare the needed DLL's
Declare Integer SHFileOperation In Shell32 ;
String @lpFileOp
DECLARE Long GlobalAlloc IN WIN32API Long, Long
DECLARE Long GlobalFree IN WIN32API Long

lcFrom = "D:\SourceFolder\*" + CHR(0) + CHR(0)
hGlobalFrom = GlobalAlloc(0x0040, LEN(lcFrom))
SYS(2600, hGlobalFrom, LEN(lcFrom), lcFrom)

lcTo = "\\xpsrv1\targetfolder\" + CHR(0) + CHR(0)
hGlobalTo = GlobalAlloc(0x0040, LEN(lcTo))
SYS(2600, hGlobalTo, LEN(lcTo), lcTo)

lcTitle = "Copy FILE(s)..." + CHR(0) + CHR(0)
hGlobalTitle = GlobalAlloc(0x0040, LEN(lcTitle))
SYS(2600, hGlobalTitle, LEN(lcTitle), lcTitle)

Local shFileOp As String && SHFILEOPSTRUCT
lnFlag = FOF_CONFIRMMOUSE ;
+ FOF_NOERRORUI ;
+ FOF_RENAMEONCOLLISION ;
+ FOF_MULTIDESTFILES ;
+ FOF_SIMPLEPROGRESS ;
+ FOF_NOCOPYSECURITYATTRIBS ;
+ FOF_NOCONFIRMMKDIR ;
+ FOF_NOCONFIRMATION
shFileOp = BinToC(_vfp.HWnd, "4RS") + ;
BINTOC(FO_MOVE, "4RS") + ;
BINTOC(hGlobalFrom, "4RS") + ;
BINTOC(hGlobalTo, "4RS") + ;
BINTOC(lnFlag, "2RS") + ;
CHR(0) + CHR(0) + CHR(0) + CHR(0) + ;
CHR(0) + CHR(0) + CHR(0) + CHR(0) + ;
BINTOC(hGlobalTitle, "4RS")

IF SHFileOperation(@shFileOp) = 0
?"files copied!"
ELSE
?"Error while copying..."
ENDIF

GlobalFree(hGlobalFrom)
GlobalFree(hGlobalTo)
GlobalFree(hGlobalTitle)

**********************************************************
Post by Lew Schwartz
-----Original Message-----
Sent: donderdag 31 augustus 2006 22:10
Subject: RE: Move directories
Post by Chet Gardiner
I think he's trying to do it in a VFP program...?
Exactly, there are a few thousand directories, moving each
one manually might take some time ;)
Post by Chet Gardiner
why not xcopy /E to include all the empty folders as well as all
folders with files?
Because we don't want the whole lot moved only a selection of
them; those that have a certain string (year) in their name.
Post by Chet Gardiner
Fox's rename will move files across drives, but you'll have
to handle
Post by Chet Gardiner
the directory structures with adir(<AA>,<path+*.*>,"D") & md.
(Currently working on a fox version of xcopy).
Fox version of XCopy would be _extremely_ interesting.
Rgds,
Nick
[excessive quoting removed by server]
Nick
2006-09-01 13:25:55 UTC
Permalink
Post by Sietse Wijnker
It uses the SHFileOperation API which is also used when dragging files from
one folder to another in winexplorer.
Regards,
Sietse Wijnker
Thanks for that Sietse, this is the nearest I have been to having a fully
working example.

The only problem I have with this is that it errors if all the directories
in the To path do not exist. I assumed that they would simply be created
but that does not appear to be the case.

For example:
lcFrom = "\\Server\Data\Documents\Test"
lcTo = "\\Server\Archive\Data\Documents\Test"
Will fail unless the
\\Server\Archive
\\Server\Archive\Data
\\Server\Archive\Data\Documents
Directories are first created

Cheers,
Nick
Chris Davis
2006-09-01 13:46:58 UTC
Permalink
Hmm I seem to think I have a routine in fox which does this, would you like
me to dig it out or you not looking for a fox solution.

-----Original Message-----
From: profoxtech-***@leafe.com [mailto:profoxtech-***@leafe.com] On
Behalf Of Nick
Sent: 01 September 2006 14:26
To: ***@leafe.com
Subject: RE: Move directories
Post by Sietse Wijnker
It uses the SHFileOperation API which is also used when dragging files from
one folder to another in winexplorer.
Regards,
Sietse Wijnker
Thanks for that Sietse, this is the nearest I have been to having a fully
working example.

The only problem I have with this is that it errors if all the directories
in the To path do not exist. I assumed that they would simply be created
but that does not appear to be the case.

For example:
lcFrom = "\\Server\Data\Documents\Test"
lcTo = "\\Server\Archive\Data\Documents\Test"
Will fail unless the
\\Server\Archive
\\Server\Archive\Data
\\Server\Archive\Data\Documents
Directories are first created

Cheers,
Nick




[excessive quoting removed by server]
Nick
2006-09-01 13:52:48 UTC
Permalink
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
Chris Davis
2006-09-01 14:11:14 UTC
Permalink
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: profoxtech-***@leafe.com [mailto:profoxtech-***@leafe.com] On
Behalf Of Nick
Sent: 01 September 2006 14:53
To: ***@leafe.com
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]
Ted Roche
2006-09-02 13:27:58 UTC
Permalink
So we're all trying to write our own software that's kind of like
rsync, only slower. And more error-prone.

Rsync:http://en.wikipedia.org/wiki/Rsync

Why are people using a database scripting language to perform an OS-level task?

VFP can serve as a general purpose programming language in a pinch,
but there is a world of free, simple, easy-to-use languages out there.
Writing it all in VFP is a symptom of NIH.

"Those who do not understand Unix are condemned to reinvent it, poorly."
-- Henry Spencer Usenet signature, November 1987
http://www.faqs.org/docs/artu/philosophychapter.html
--
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com
Chet Gardiner
2006-09-02 19:37:58 UTC
Permalink
Post by Ted Roche
So we're all trying to write our own software that's kind of like
rsync, only slower. And more error-prone.
Rsync:http://en.wikipedia.org/wiki/Rsync
Why are people using a database scripting language to perform an OS-level task?
Can you say "learning curve", children...
Post by Ted Roche
VFP can serve as a general purpose programming language in a pinch,
but there is a world of free, simple, easy-to-use languages out there.
Writing it all in VFP is a symptom of NIH.
"Those who do not understand Unix are condemned to reinvent it, poorly."
-- Henry Spencer Usenet signature, November 1987
http://www.faqs.org/docs/artu/philosophychapter.html
Not to mention how long would it take to install rsync on a windoze machine?
Ted Roche
2006-09-02 19:42:19 UTC
Permalink
Post by Chet Gardiner
Not to mention how long would it take to install rsync on a windoze machine?
You mean, like, by using one of the pre-built installers available
from the links on the original post? A couple of minutes, at least.
And maybe a reboot. It is Windows, after all...
--
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com
Nick
2006-09-02 20:13:30 UTC
Permalink
You seem to be missing the point somewhat. It was not about synchronizing a
whole directory structure just a specific few directories (with their
subdirectories and file) that meet certain criteria, say those last modified
over a year ago.

Nick
Post by Lew Schwartz
-----Original Message-----
Of Ted Roche
Sent: 02 September 2006 20:42
Subject: Re: Move directories
Post by Chet Gardiner
Not to mention how long would it take to install rsync on a windoze
machine?
You mean, like, by using one of the pre-built installers available
from the links on the original post? A couple of minutes, at least.
And maybe a reboot. It is Windows, after all...
--
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com
[excessive quoting removed by server]
Eugene Vital
2006-09-03 13:08:26 UTC
Permalink
Post by Lew Schwartz
-----Original Message-----
Sent: Saturday, September 02, 2006 4:14 PM
To: 'ProFox Email List'
Subject: RE: Move directories
You seem to be missing the point somewhat. It was not about
synchronizing a
whole directory structure just a specific few directories (with their
subdirectories and file) that meet certain criteria, say
those last modified
over a year ago.
I recently had a similar task and was looking at RSYNC as the solution however you can't filter RSYNC
operations with a date range so I ended up using ROBOCOPY with great success.

I can't disclose the details but it scans a large number of directories looking for new files, it has to sort
through about 4 million files and on average finds about 20,000 new files daily to sync up. The whole operation
takes less than 2 hours.

From what I read it will be included in Vista if/when it is released :-P

You can download it from M$FT and if you Google it you will find plenty of examples.



http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
Post by Lew Schwartz
Nick
Post by Lew Schwartz
-----Original Message-----
Of Ted Roche
Sent: 02 September 2006 20:42
Subject: Re: Move directories
Post by Chet Gardiner
Not to mention how long would it take to install rsync on
a windoze
Post by Lew Schwartz
machine?
You mean, like, by using one of the pre-built installers available
from the links on the original post? A couple of minutes, at least.
And maybe a reboot. It is Windows, after all...
--
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com
[excessive quoting removed by server]
Nick
2006-09-05 13:59:26 UTC
Permalink
Chris, thanks for that routine.

Although I have solved the current task without it you routine looked
interesting and potentially quite useful so I thought I would test it out a
bit further. I found it necessary to make a couple of changes:
1). Impersonate Administrator user & then reset to normal user when
complete.
2). Create a SyncErr cursor to record failures.
3). Test if each action is successful, else write to aforementioned cursor.
4). Record file/directory attributes so we can establish which are read-only
when updating or deleting.
5). Remove read-only attribute when necessary.

Outstanding problem:
If a directory is to be deleted and the files in it are read-only then:
DELETE FILE *.* in AGRD() fails. Need to find a way to either remove
read-only attrib from all files in a directory or loop through all files
removing it one by one.

Regards,
Nick


New updated but untidy code below:

* Impersonate user code from the Fox Wiki by Hugo Ranea
#define LOGON32_PROVIDER_DEFAULT 0
#define LOGON32_LOGON_INTERACTIVE 2
#define LOGON32_LOGON_NETWORK 3
#define LOGON32_LOGON_BATCH 4
#define LOGON32_LOGON_SERVICE 5
#define LOGON32_LOGON_UNLOCK 7

DECLARE integer LogonUser IN AdvApi32.DLL;
string szUsername,;
string lpszDomain,;
string lpszPassword,;
integer dwLogonType,;
integer dwLogonProvider,;
integer @phToken

DECLARE integer ImpersonateLoggedOnUser IN AdvApi32.DLL integer hToken
DECLARE integer RevertToSelf IN AdvApi32.DLL

CLEAR

local nToken
nToken = 0
?
LogonUser("Administrator","MyServer","NotMyAdminPassword:)",LOGON32_LOGON_IN
TERACTIVE, LOGON32_PROVIDER_DEFAULT, @nToken)
? nToken

? ImpersonateLoggedOnUser(nToken)

CREATE CURSOR SyncErr (ctype c(1),csource m(10),ccopy m(10),cAttribs c(6))

SET ESCAPE ON
SET MESSAGE TO

DO Sync WITH "C:\Data", "D:\Archive"

? RevertToSelf()

RETURN


PROCEDURE Sync
LPARAMETERS lcsource,lccopy

? "Syncronising: ",lcsource," to ",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),cAttribs
c(6))

?? " Examining differences..."
m.Start=SECONDS()
SET MESSAGE TO
=proc_sync(lcsource,lccopy)
?? " took: ",ALLTRIM(STR(SECONDS()-m.Start,10,3)),"secs - "
?? " Updating..."
m.Start=SECONDS()
SELECT sync
SCAN
SCATTER MEMVAR memo
IF "R"$cAttribs
? "removing read-only: ",m.cCopy
SetFileAttribs(m.ccopy, "r") && turn Off
Read-only
ENDIF
DO CASE
CASE ctype="C"
COPY FILE (m.csource) TO (m.ccopy)
IF FILE(m.ccopy)
SET MESSAGE TO "Copied file:
"+m.ccopy
ELSE
INSERT INTO SyncErr FROM MEMVAR
ENDIF
CASE ctype="D"
MD (m.ccopy)
IF DIRECTORY(m.ccopy)
SET MESSAGE TO "Created directory:
"+m.ccopy
ELSE
INSERT INTO SyncErr FROM MEMVAR
ENDIF
CASE ctype="U"
DELETE FILE (m.ccopy)
IF FILE(m.ccopy)
INSERT INTO SyncErr FROM MEMVAR
ELSE
COPY FILE (m.csource) TO (m.ccopy)
IF FILE(m.ccopy)
SET MESSAGE TO "Updated
file: "+m.ccopy
ELSE
INSERT INTO SyncErr FROM
MEMVAR
ENDIF
ENDIF
CASE ctype="X"
DELETE FILE (m.ccopy)
IF FILE(m.ccopy)
INSERT INTO SyncErr FROM MEMVAR
ELSE
SET MESSAGE TO "Deleted file:
"+m.ccopy
ENDIF
CASE ctype="Z"
=AGRD (m.ccopy)
RD (m.ccopy)
IF DIRECTORY(m.ccopy)
INSERT INTO SyncErr FROM MEMVAR
ELSE
SET MESSAGE TO "Removed directory:
"+m.ccopy
ENDIF
ENDCASE
ENDSCAN
?? " took: ",ALLTRIM(STR(SECONDS()-m.Start,10,3)),"secs."
ENDIF

RETURN lcreturn

ENDPROC

***

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,cAttribs);
VALUES
(lcaction,ALLTRIM(lcsource)+"\"+ALLTRIM(lafiles(lncounter,1)),ALLTRIM(lccopy
)+"\"+ALLTRIM(lafiles(lncounter,1)),ALLTRIM(lafiles(lncounter,5)))
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,cAttribs);
VALUES
(lcaction,"",ALLTRIM(lccopy)+"\"+ALLTRIM(lacopies(lncounter,1)),ALLTRIM(laco
pies(lncounter,5)))
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

PROCEDURE SetFileAttribs
LPARAMETERS pcFile, pcAttr

* Author: William GC Steinford 2003
* Takes a file and a list of attributes to change on the file, and does the
change
*
* pcFile : either just the file name or the full path to the file.
* Either way, the full path will be resolved using FULLPATH()
* pcAttrs : a list of attributes to change on the file
* if the attribute character is Uppercase it will be turned on,
* Lowercase, it will be turned off,
* Not listed, it will be left alone.
* a,A - Archive
* s,S - System
* h,H - Hidden
* r,R - Read Only
* i,I - Not Content-Indexed
* t,T - Temporary Storage (try to keep in memory)
* N - Normal (clear all other attributes)

*!* BOOL SetFileAttributes(
*!* LPCTSTR lpFileName, // file name
*!* DWORD dwFileAttributes // attributes
*!* )
*!* DWORD GetFileAttributes(
*!* LPCTSTR lpFileName // name of file or directory
*!* )

#define FILE_ATTRIBUTE_READONLY 0x00000001
#define FILE_ATTRIBUTE_HIDDEN 0x00000002
#define FILE_ATTRIBUTE_SYSTEM 0x00000004
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
#define FILE_ATTRIBUTE_ENCRYPTED 0x00000040
#define FILE_ATTRIBUTE_NORMAL 0x00000080
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
#define FILE_ATTRIBUTE_OFFLINE 0x00001000
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000

DECLARE INTEGER GetFileAttributes IN kernel32;
STRING lpFileName
DECLARE SHORT SetFileAttributes IN kernel32;
STRING lpFileName,;
INTEGER dwFileAttributes

LOCAL lcFile, lnAttr, lcAttr, laDir[1]
lcFile = FULLPATH(pcFile)
* File() doesn't see Hidden or system files: if NOT FILE(pcFile)
IF adir(laDir,lcFile,'DHS')=0
RETURN .F.
endif
lcAttr = upper(pcAttr)

if 'N' $ pcAttr
* "NORMAL" must be used alone.
lnRes = SetFileAttributes(lcFile,FILE_ATTRIBUTE_NORMAL)
RETURN (lnRes<>0)
endif

lnAttr = GetFileAttributes( lcFile )
* These attributes Can't be set using SetFileAttributes:
lnAttr = BitAnd( lnAttr, BitNot( FILE_ATTRIBUTE_COMPRESSED ;
+ FILE_ATTRIBUTE_DIRECTORY + FILE_ATTRIBUTE_ENCRYPTED ;
+ FILE_ATTRIBUTE_REPARSE_POINT ;
+ FILE_ATTRIBUTE_SPARSE_FILE ) )
if 'A' $ lcAttr
if 'A' $ pcAttr
lnAttr = BitOr( lnAttr, FILE_ATTRIBUTE_ARCHIVE )
else
lnAttr = BitAnd( lnAttr, BitNot(FILE_ATTRIBUTE_ARCHIVE) )
endif
endif
if 'R' $ lcAttr
if 'R' $ pcAttr
lnAttr = BitOr( lnAttr, FILE_ATTRIBUTE_READONLY )
else
lnAttr = BitAnd( lnAttr, BitNot(FILE_ATTRIBUTE_READONLY) )
endif
endif
if 'H' $ lcAttr
if 'H' $ pcAttr
lnAttr = BitOr( lnAttr, FILE_ATTRIBUTE_HIDDEN )
else
lnAttr = BitAnd( lnAttr, BitNot(FILE_ATTRIBUTE_HIDDEN) )
endif
endif
if 'S' $ lcAttr
if 'S' $ pcAttr
lnAttr = BitOr( lnAttr, FILE_ATTRIBUTE_SYSTEM )
else
lnAttr = BitAnd( lnAttr, BitNot(FILE_ATTRIBUTE_SYSTEM) )
endif
endif
if 'I' $ lcAttr
if 'I' $ pcAttr
lnAttr = BitOr( lnAttr, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED )
else
lnAttr = BitAnd( lnAttr, BitNot(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) )
endif
endif
if 'T' $ lcAttr
if 'S' $ pcAttr
lnAttr = BitOr( lnAttr, FILE_ATTRIBUTE_TEMPORARY )
else
lnAttr = BitAnd( lnAttr, BitNot(FILE_ATTRIBUTE_TEMPORARY) )
endif
endif
if 'N' $ lcAttr
lnAttr = iif('N'$pcAttr, FILE_ATTRIBUTE_NORMAL, lnAttr )
endif

lnRes = SetFileAttributes(lcFile,lnAttr)
RETURN (lnRes<>0)

FUNCTION GetFileAttrib( tcFName )
*GetFileAttrib( cFName ) Return the File Attributes (RSHA)
*!* DWORD GetFileAttributes(
*!* LPCTSTR lpFileName // name of file or directory
*!* )
DECLARE LONG GetFileAttributes IN Win32Api AS util_GetFileAttributes ;
STRING LPCTSTR_lpFileName
LOCAL lnAttr, lcAttr
lnAttr = util_GetFileAttributes( tcFName )
CLEAR DLLS util_GetFileAttributes
if lnAttr=0xFFFF
RETURN 'error'
ENDIF
lcAttr = iif( BITAND(lnAttr,util_FILE_ATTRIBUTE_READONLY )>0, 'R', '' ) ;
+ iif( BITAND(lnAttr,util_FILE_ATTRIBUTE_HIDDEN )>0, 'H', '' ) ;
+ iif( BITAND(lnAttr,util_FILE_ATTRIBUTE_SYSTEM )>0, 'S', '' ) ;
+ iif( BITAND(lnAttr,util_FILE_ATTRIBUTE_ARCHIVE )>0, 'A', '' ) ;
+ iif( BITAND(lnAttr,util_FILE_ATTRIBUTE_DIRECTORY)>0, 'D', '' )
RETURN lcAttr
ENDFUNC

************************ end ******************************

Tracy Pearson
2006-09-01 13:43:52 UTC
Permalink
VFP's MD will create the whole level from one command.
IF NOT DIRECTORY(targetDirectory)
MD (targetDirectory)
ENDIF

Tracy
Post by Lew Schwartz
-----Original Message-----
From: Nick
Sent: Friday, September 01, 2006 9:26 AM
Subject: RE: Move directories
Post by Sietse Wijnker
It uses the SHFileOperation API which is also used when
dragging files
Post by Sietse Wijnker
from one folder to another in winexplorer.
Regards,
Sietse Wijnker
Thanks for that Sietse, this is the nearest I have been to
having a fully working example.
The only problem I have with this is that it errors if all
the directories in the To path do not exist. I assumed that
they would simply be created but that does not appear to be the case.
lcFrom = "\\Server\Data\Documents\Test"
lcTo = "\\Server\Archive\Data\Documents\Test"
Will fail unless the
\\Server\Archive
\\Server\Archive\Data
\\Server\Archive\Data\Documents
Directories are first created
Cheers,
Nick
Nick
2006-09-01 16:45:00 UTC
Permalink
Post by Tracy Pearson
VFP's MD will create the whole level from one command.
IF NOT DIRECTORY(targetDirectory)
MD (targetDirectory)
ENDIF
Almost there! Only problem with MD is that it creates all the directories
in _lower_ case rather than the mixed case that they were in. Can't think
of a way around this at the moment, any ideas?

Cheers,
Nick
Richard Kaye
2006-09-01 17:28:07 UTC
Permalink
Back to the WinAPI if you want to preserve case, I believe.

DECLARE INTEGER CreateDirectory IN kernel32;
STRING lpPathName,;
INTEGER lpSecurityAttributes

?CreateDirectory("c:\Testing123",0)
?CreateDirectory("c:\TESTING456",0)
Post by Nick
Almost there! Only problem with MD is that it creates all the directories
in _lower_ case rather than the mixed case that they were in. Can't think
of a way around this at the moment, any ideas?
--
Richard Kaye
Artfact/RFC Systems
Voice: 617.219.1038
Fax: 617.219.1001

For the fastest response time, please send your support
queries to:

Technical Support - ***@rfcsystems.com
Australian Support - ***@rfcsystems.com
Internet Support - ***@rfcsystems.com
All Other Requests - ***@rfcsystems.com

---------------------------------------------------------
This message has been checked for viruses before sending.
---------------------------------------------------------
Nick
2006-09-01 18:33:37 UTC
Permalink
Problem is CreateDirectory() only creates one single directory if all
subdirectories are in place, it does not create a chain of them!

Nick
Post by Lew Schwartz
-----Original Message-----
Of Richard Kaye
Sent: 01 September 2006 18:28
Subject: Re: Move directories
Back to the WinAPI if you want to preserve case, I believe.
DECLARE INTEGER CreateDirectory IN kernel32;
STRING lpPathName,;
INTEGER lpSecurityAttributes
?CreateDirectory("c:\Testing123",0)
?CreateDirectory("c:\TESTING456",0)
Post by Nick
Almost there! Only problem with MD is that it creates all the
directories
Post by Nick
in _lower_ case rather than the mixed case that they were in. Can't
think
Post by Nick
of a way around this at the moment, any ideas?
--
Richard Kaye
Artfact/RFC Systems
Voice: 617.219.1038
Fax: 617.219.1001
For the fastest response time, please send your support
---------------------------------------------------------
This message has been checked for viruses before sending.
---------------------------------------------------------
[excessive quoting removed by server]
Tracy Pearson
2006-09-01 18:43:11 UTC
Permalink
Post by Lew Schwartz
-----Original Message-----
From: Nick
Sent: Friday, September 01, 2006 2:34 PM
Subject: RE: Move directories
Problem is CreateDirectory() only creates one single
directory if all subdirectories are in place, it does not
create a chain of them!
Nick
Parse your directory structure with ALines() then loop or loop with
GetWordCount() and GetWordNum().
Then use the CreateDirectory API call inside the loop.

Tracy
Charlie Coleman
2006-09-01 18:16:12 UTC
Permalink
Post by Nick
Post by Tracy Pearson
VFP's MD will create the whole level from one command.
IF NOT DIRECTORY(targetDirectory)
MD (targetDirectory)
ENDIF
Almost there! Only problem with MD is that it creates all the directories
in _lower_ case rather than the mixed case that they were in. Can't think
of a way around this at the moment, any ideas?
Yes. DROP the concept of case-sensitivity in regards to file/directory
names. This is one of the dumbest concepts around, IMO (and as much as I
like Linux I think it's still dumb). I can NEVER imagine that I would want
a file named Myimporantdoc.odt to be separate from myimportantdoc.odt or
MyImportantDoc.odt. In fact, I think it's downright 'dangerous' to
non-technical users.

If you want 'pretty' things for your users, implement a naming convention
that you can parse in your user interface (you don't let them directly use
Windows Explorer do you? uh-oh). E.g. separate words with underscores
(spaces - Ack - another stupid idea for file names). So then you'd do
something like

Method MakePrettyFN(cRealFN)

RETURN STRTRAN(PROPER(STRTRAN(crealfn,'_',' ')), ' ', '_')

So my_important_doc.odt, My_important_DOC.odt, and MY_IMPORTANT_DOC.ODT
would all come out as My_Important_Doc.odt.

You could parse the pieces of the path the same way and you could add a
bunch more stuff in there to handle other filename stuff (like, ugh, in
case they used spaces).

Yes, I'm having a rough day..... :-)

-Charlie
Nick
2006-09-04 15:09:21 UTC
Permalink
The final solution, well the one I used anyway, was Sietse's SHFileOperation
suggestion combined with a DOS MD for creating all lower level directories
that do not exist.

The only remaining failure is that it seems to be limited to a full filepath
of 255 characters and some of my paths are longer than that. Still apart
from that restriction it all worked fine.

Thanks to all for you help.

Nick
Charlie Coleman
2006-08-31 20:35:28 UTC
Permalink
Post by Nick
Post by Chet Gardiner
I think he's trying to do it in a VFP program...?
Exactly, there are a few thousand directories, moving each one manually
might take some time ;)
...

I suggest MoveFile (in the Win32 API) for the actual 'move' step. Some
examples below

*-- MoveFile API - this will 'move' files and actually move directories
*-- Sample Call:
*-- MoveFile('C:\test\source\one', 'c:\test\new\one')
DECLARE INTEGER MoveFile IN WIN32API STRING @cFrom, STRING @cTo


Example call:
nX = MoveFile("C:\original\folder\place", "c:\new\folder\place")

Note: the string should *not* have a trailing backslash.

HTH,
-Charlie
Nick
2006-09-01 10:46:37 UTC
Permalink
Post by Charlie Coleman
I suggest MoveFile (in the Win32 API) for the actual 'move' step. Some
examples below
Again it only does individual files not directories with subdirectories.

Nick
Rob Anderson
2006-09-01 11:26:18 UTC
Permalink
How about something along the lines of :-

o = CreateObject("scripting.filesystemobject")
o.CopyFolder("c:\cvp", "t:\")
o.DeleteFolder("c:\cvp")

HTH,

Robbo.

-----Original Message-----
From: profox-***@leafe.com [mailto:profox-***@leafe.com] On
Behalf Of Nick
Sent: 01 September 2006 11:47
To: 'ProFox Email List'
Subject: RE: Move directories
Post by Charlie Coleman
I suggest MoveFile (in the Win32 API) for the actual 'move' step. Some
examples below
Again it only does individual files not directories with subdirectories.

Nick



_______________________________________________
Post Messages to: ***@leafe.com
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.

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

______________________________________________________________________
Pegasus Software Limited is an Infor company.

This e-mail is from Pegasus Software Limited. The e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom it is addressed. If you have received this e-mail in error you must not copy, distribute or take any action in reliance on it. Please notify the sender by e-mail or telephone.

Pegasus Software Limited utilises an anti-virus system and therefore any files sent via e-mail will have been checked for known viruses. You are however advised to run your own virus check before opening any attachments received as Pegasus Software Limited will not in any event accept any liability whatsoever once an e-mail and/or any attachment is received.

This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
Nick
2006-09-01 12:51:38 UTC
Permalink
Post by Rob Anderson
How about something along the lines of :-
o = CreateObject("scripting.filesystemobject")
o.CopyFolder("c:\cvp", "t:\")
o.DeleteFolder("c:\cvp")
Works ok for small tests but not robust enough for use in a real
application.

For example:
o = CreateObject("scripting.filesystemobject")
o.CopyFolder("\\Server\Data\Documents\Test2",
"\\Server\Archive\Data\Documents\Test2")

Fails with OLE error code 0x800a004c. Unknown COM status code.

Any ideas why?
Rob Anderson
2006-09-01 13:17:41 UTC
Permalink
Doing a google for "0x800a004c"

Indicates a path not found error msg - do any of these articles help at
all.

http://www.google.co.uk/search?sourceid=navclient&ie=UTF-8&rls=GGLJ,GGLJ
:2006-32,GGLJ:en&q=0x800a004c

(Watch for word wrap)

Robbo.

-----Original Message-----
From: profox-***@leafe.com [mailto:profox-***@leafe.com] On
Behalf Of Nick
Sent: 01 September 2006 13:52
To: 'ProFox Email List'
Subject: RE: Move directories
Post by Rob Anderson
How about something along the lines of :-
o = CreateObject("scripting.filesystemobject")
o.CopyFolder("c:\cvp", "t:\")
o.DeleteFolder("c:\cvp")
Works ok for small tests but not robust enough for use in a real
application.

For example:
o = CreateObject("scripting.filesystemobject")
o.CopyFolder("\\Server\Data\Documents\Test2",
"\\Server\Archive\Data\Documents\Test2")

Fails with OLE error code 0x800a004c. Unknown COM status code.

Any ideas why?



_______________________________________________
Post Messages to: ***@leafe.com
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.

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

______________________________________________________________________
Pegasus Software Limited is an Infor company.

This e-mail is from Pegasus Software Limited. The e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom it is addressed. If you have received this e-mail in error you must not copy, distribute or take any action in reliance on it. Please notify the sender by e-mail or telephone.

Pegasus Software Limited utilises an anti-virus system and therefore any files sent via e-mail will have been checked for known viruses. You are however advised to run your own virus check before opening any attachments received as Pegasus Software Limited will not in any event accept any liability whatsoever once an e-mail and/or any attachment is received.

This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
Rob Anderson
2006-09-01 13:18:42 UTC
Permalink
Also, this one :-

http://www.tek-tips.com/viewthread.cfm?qid=1106669&page=1

Robbo



-----Original Message-----
From: profox-***@leafe.com [mailto:profox-***@leafe.com] On
Behalf Of Nick
Sent: 01 September 2006 13:52
To: 'ProFox Email List'
Subject: RE: Move directories
Post by Rob Anderson
How about something along the lines of :-
o = CreateObject("scripting.filesystemobject")
o.CopyFolder("c:\cvp", "t:\")
o.DeleteFolder("c:\cvp")
Works ok for small tests but not robust enough for use in a real
application.

For example:
o = CreateObject("scripting.filesystemobject")
o.CopyFolder("\\Server\Data\Documents\Test2",
"\\Server\Archive\Data\Documents\Test2")

Fails with OLE error code 0x800a004c. Unknown COM status code.

Any ideas why?



_______________________________________________
Post Messages to: ***@leafe.com
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.

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

______________________________________________________________________
Pegasus Software Limited is an Infor company.

This e-mail is from Pegasus Software Limited. The e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom it is addressed. If you have received this e-mail in error you must not copy, distribute or take any action in reliance on it. Please notify the sender by e-mail or telephone.

Pegasus Software Limited utilises an anti-virus system and therefore any files sent via e-mail will have been checked for known viruses. You are however advised to run your own virus check before opening any attachments received as Pegasus Software Limited will not in any event accept any liability whatsoever once an e-mail and/or any attachment is received.

This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
Nick
2006-09-01 15:55:28 UTC
Permalink
Rob,

Sometimes works sometimes doesn't, have checked the paths and all ok. It
seems to be a timing issue when using UNC network paths, if I have a couple
of explorer windows open one each for the source/destination then all works
fine otherwise seems to be a 50/50 chance of returning the OLE error. I
suspect the FileSystemObject may be ok with local files but is too flaky for
production use over the network.

Cheers,
Nick
Post by Lew Schwartz
-----Original Message-----
Of Rob Anderson
Sent: 01 September 2006 14:19
To: ProFox Email List
Subject: RE: Move directories
Also, this one :-
http://www.tek-tips.com/viewthread.cfm?qid=1106669&page=1
Robbo
-----Original Message-----
Behalf Of Nick
Sent: 01 September 2006 13:52
To: 'ProFox Email List'
Subject: RE: Move directories
Post by Rob Anderson
How about something along the lines of :-
o = CreateObject("scripting.filesystemobject")
o.CopyFolder("c:\cvp", "t:\")
o.DeleteFolder("c:\cvp")
Works ok for small tests but not robust enough for use in a real
application.
o = CreateObject("scripting.filesystemobject")
o.CopyFolder("\\Server\Data\Documents\Test2",
"\\Server\Archive\Data\Documents\Test2")
Fails with OLE error code 0x800a004c. Unknown COM status code.
Any ideas why?
[excessive quoting removed by server]
Charlie Coleman
2006-09-01 15:05:35 UTC
Permalink
Post by Nick
Post by Charlie Coleman
I suggest MoveFile (in the Win32 API) for the actual 'move' step. Some
examples below
Again it only does individual files not directories with subdirectories.
Acutally, it will move the folder and everything under it. For example, I
did this as a test:

Folders:

c:\testing\orig\
c:\testing\orig\onedown
c:\testing\orig\twodown

c:\testing\new\


Each one of the folders under c:\testing\orig\ had some files in them.

Then I did a movefile("c:\testing\orig\onedown", "c:\testing\new\onedown")

And I got this:

c:\testing\new\
c:\testing\new\onedown
c:\testing\new\twodown

And all the files came along.


-Charlie
Nick
2006-09-01 15:33:07 UTC
Permalink
Charlie,

Just tried MoveFile() again for a sanity check, same problems as before:
1). Does not allow move across drives.
2). Does not support UNC network path names.

Nick
Post by Lew Schwartz
-----Original Message-----
Of Charlie Coleman
Sent: 01 September 2006 16:06
To: ProFox Email List
Subject: RE: Move directories
Post by Nick
Post by Charlie Coleman
I suggest MoveFile (in the Win32 API) for the actual 'move' step. Some
examples below
Again it only does individual files not directories with subdirectories.
Acutally, it will move the folder and everything under it. For example, I
c:\testing\orig\
c:\testing\orig\onedown
c:\testing\orig\twodown
c:\testing\new\
Each one of the folders under c:\testing\orig\ had some files in them.
Then I did a movefile("c:\testing\orig\onedown", "c:\testing\new\onedown")
c:\testing\new\
c:\testing\new\onedown
c:\testing\new\twodown
And all the files came along.
-Charlie
[excessive quoting removed by server]
Charlie Coleman
2006-09-01 15:46:19 UTC
Permalink
Post by Nick
Charlie,
1). Does not allow move across drives.
2). Does not support UNC network path names.
Nick
Yep. Sorry. I meant to mention that in my previous email (got called by a
'jerk' at work for waste-of-time-phone conf).

Can't cross drives and can't use UNCs. But it will take all the files and
subdirs <g>.

Hope I didn't waste too much of everyone's time....

-Charlie
Lew Schwartz
2006-08-31 19:17:58 UTC
Permalink
Fox's rename will move files across drives, but you'll have to handle
the directory structures with adir(<AA>,<path+*.*>,"D") & md. (Currently
working on a fox version of xcopy).

-----Original Message-----
From: profoxtech-***@leafe.com [mailto:profoxtech-***@leafe.com]
On Behalf Of Chet Gardiner
Sent: Thursday, August 31, 2006 3:07 PM
To: ***@leafe.com
Subject: Re: Move directories

I think he's trying to do it in a VFP program...?
Post by Jim Winter
Post by Nick Causton
Any suggestions how I can move a directory (including any
subdirectories and
files) from one drive to another?
MoveFile Win32API - will not move across drives, also does not like
UNC file paths WScript.Shell - Fails with OLE error code
0x800a0046/004c/003a if directory has multiple subdirectories XCOPY -
RUN command fails because command length > 256 characters (very long
directory/file names)
Nick
Nick,
Just open up 2 copies of Windows Explorer, shift + left click on the
directory you want to move, drag it to the second copy of Explorer and
drop it on the new drive.
Regards,
Jim
[excessive quoting removed by server]
Dave Thayer
2006-08-31 20:32:13 UTC
Permalink
Any suggestions how I can move a directory (including any subdirectories...
Have you tried robocopy? It's part of the windows resource kit and is
said to be a lot more robust than xcopy. I'd use a win32 port of
rsync myself, but have heard a lot of good things about robocopy.

<http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en>
or
<http://tinyurl.com/6csco>

dt
--
Dave Thayer
Denver, CO
Nick
2006-09-01 10:44:55 UTC
Permalink
Post by Dave Thayer
Have you tried robocopy? It's part of the windows resource kit and is
said to be a lot more robust than xcopy. I'd use a win32 port of
rsync myself, but have heard a lot of good things about robocopy.
Interesting, didn't know that existed, will download and give it a try.

Nick
Lew Schwartz
2006-08-31 21:04:14 UTC
Permalink
I haven't tested all of the win api alternatives, but judging from the
ones I have tested, I'd guess that all fox disk io functions use the
api, too. I guess this is a bit of a no brainer, since I seem to
remember that talking to disk drives _only_ through winapi was an
innovation in a previous version of windows. Seem reasonable.

-----Original Message-----
From: profoxtech-***@leafe.com [mailto:profoxtech-***@leafe.com]
On Behalf Of Charlie Coleman
Sent: Thursday, August 31, 2006 4:35 PM
To: ***@leafe.com
Subject: RE: Move directories
Post by Nick
Post by Chet Gardiner
I think he's trying to do it in a VFP program...?
Exactly, there are a few thousand directories, moving each one manually
might take some time ;)
...

I suggest MoveFile (in the Win32 API) for the actual 'move' step. Some
examples below

*-- MoveFile API - this will 'move' files and actually move directories
*-- Sample Call:
*-- MoveFile('C:\test\source\one', 'c:\test\new\one')
DECLARE INTEGER MoveFile IN WIN32API STRING @cFrom, STRING @cTo


Example call:
nX = MoveFile("C:\original\folder\place", "c:\new\folder\place")

Note: the string should *not* have a trailing backslash.

HTH,
-Charlie




[excessive quoting removed by server]
Ted Roche
2006-09-01 13:47:18 UTC
Permalink
Post by Nick Causton
Any suggestions how I can move a directory (including any subdirectories and
files) from one drive to another?
XCOPY - RUN command fails because command length > 256 characters (very long
directory/file names)
Rather than invoking XCOPY directly, how about using VFP TextMerge to
write a batch file and then invoke that from VFP? Eliminates the path
problems. You will have to consider error handling, though: perhaps
capture the error return in the batch file and write out an error log.
--
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com
Chet Gardiner
2006-09-02 01:07:56 UTC
Permalink
If I had to start from scratch...

I'd use my own dirsubs.prg routine to fill a foxpro cursor with all of
the files in all of the folders/subfolders in the from directory.

Then I'd;

1) SELECT and group by subfolder into another cursor
2) Build the complete directory tree on the destination drive
3) Copy each file in the original cursor to the destination folder/filename
with "Copy FILE <from> TO <to>
logging any that don't copy -- on error...

The dirsubs routine is included in my chkstr.zip on the leafe.com
download site or can be downloaded from
www.chetgardiner.com/dirsubs.zip (in about 5 minutes -- 6:15pm PDT)

Chet
Post by Nick Causton
Any suggestions how I can move a directory (including any subdirectories and
files) from one drive to another?
MoveFile Win32API - will not move across drives, also does not like UNC file
paths
WScript.Shell - Fails with OLE error code 0x800a0046/004c/003a if directory
has multiple subdirectories
XCOPY - RUN command fails because command length > 256 characters (very long
directory/file names)
Nick
[excessive quoting removed by server]
Continue reading on narkive:
Loading...