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

How to Check if the Dir Exist and Copying Files on it

Status
Not open for further replies.

Wendz

Programmer
Aug 9, 2000
47
0
0
PH
Visit site
Hi To all!

I am designing a utility that will back-up files. I have a short program like this:

local tdir, sdir
sdir="c:\sps\data"
tdir="d:\sps\data"

if !empty(tdir)
wait wind "directory found" nowait
set defa to (sdir)
else
wait wind "directory not found" nowait
mkdir (tdir)
endif

My problem is it diplays directory found but it has error on setting the default directory. How do i effectively check the existing directory? How do I make a directory on the else part? is md still usable? How do I copy all the files on the source directory to the target directory? What will be the better way to do it. any recommendation?
Thanks a lot and more power to you all!

Wendz
edbb@lycos.com



 
ON ERROR DO pErrTrap WITH ERROR( ), MESSAGE( ), LINENO( ), PROGRAM( )

PROCEDURE pErrTrap
PARAMETERS nE, cM, nL, cP
IF nE= 36 then &&path not found
DO what ever
ENDIF



Pete
blindpete@mail.com

What your mother told you is true! You will go blind! (from moonshine anyway)
 
Scratch that... Here is a better way.

PROCEDURE bPathExist
PARAMETER cTargetPath
ADIR(gZ,cTargetPath + "*.*" )
IF TYPE('gZ')='U' THEN
'Path not exist
RETURN .F.
ELSE
'Path Exist
RETURN .T.
ENDIF
ENDPROC


There is API ways to do this but this is pretty straight forward too.

Pete
blindpete@mail.com

What your mother told you is true! You will go blind! (from moonshine anyway)
 
Try using the Directory() Function
[tt]
if !directory(gcNUserHtp)
md (gcNCustHtp)
endif
[/tt]


David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
The one I posted doesn't work if the directory is empty.

Pete
blindpete@mail.com

What your mother told you is true! You will go blind! (from moonshine anyway)
 
Thank you guys for your tips. I'll try to implement it and be back with the results.

Wendz
edbb@lycos.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top