Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: Andy Kramek
  Where is Andy Kramek?
 Westminster Circle, Akron
 Ohio - United States
 Andy Kramek
 To: bryan wetton
  Where is bryan wetton?
 Morphett Vale
 Australia
 bryan wetton
 Tags
Subject: RE: directory() command
Thread ID: 209882 Message ID: 209922 # Views: 42 # Ratings: 1
Version: Visual FoxPro 9 Category: General VFP Topics
Date: Thursday, January 01, 2009 1:27:50 PM         
   


> I use a 'generic' prg for backup to my server which I modify when I change the location of a project.
>
> Sometimes I make a typo in the paths so I have introduced the directory command prior to the copy.
>
>
> 
> #DEFINE SU_HOME 'mycurrentfolder'
> 
> CLOSE ALL DATABASES
> 
> public changes
> changes = ''
> 
> && remove repeatable files
> delete file *.bak
> delete file *.err
> delete file *.dat
> delete file *.txt
> delete file *.fxp
> &&- add comment to file name in changes
> do form frmbackup 
> 
> *-- Getting the date as yyyymmdd is easy. 
> lcToday = DTOS(DATE()) 
> *-- The time has colons between hours, minutes, and seconds. 
> *-- These are illegal in a file name so change them to underscores. 
> lcNow = CHRTRAN(TIME(), ':', '-') 
> lcTimeStamp = lcToday + '_at_' + subst(lcNow,1,5)
> &&  project folder with prg,forms etc all in one folder 
> lcDevDir = 'D:\DEV\_Foxpro\Projects\' + SU_HOME        
> IF DIRECTORY(lcDevDir)
> *-- The backup folder must exist 
> lcBackupDir  = '\\Nasserver209\NASDATA\Backups\Test_Backup\' + SU_HOME + '\' + lcTimeStamp + ' ' + changes
> ENDIF
> 
> ?lcBackupDir - to confirm on screen
> IF DIRECTORY(lcBackupDir)
> fso= CREATEOBJECT ('Scripting.FileSystemObject') 
> fso.CopyFolder (lcDevDir, lcBackupDir) 
> fso = null
> ?'Finished Successfully'
> ENDIF
> ?'Unsuccessful'
> 
> 

>
>
> The test IF DIRECTORY(lcBackupDir) fails but when I remove the test the copy proceeds as expected.
>
> Is there a limit on the way directory() works? Or else why does it fail here?
>
> Many thanks for any ideas.

The DIRECTORY() function takes a numeric second parameter which determine how it reports the result. When this is 0 (or unspecified) then directories with the System or Hidden attribute set are ignored (i.e. the function returns .F.). If the parameter is passed as 1 then the function always returns .T. if the directory is found on the disk.

Second if you spaces in the directory name you will need to enclose the path in quotes. This is a general rule in windows which, although it permits spaces in File and Directory names, treats a space in such a name as a terminator unless the name is quoted. So in your example the actual value of "lcBackupDir" that is tested is actually only the:

'\\Nasserver209\NASDATA\Backups\Test_Backup\' + SU_HOME + '\' + lcTimeStamp

portion - the space, and everything following it is lost which may be why DIRECTORY() is returning .F.

Try enclosing the path in quotes and it should then work as expected:

lcBackupDir  = "'" + '\\Nasserver209\NASDATA\Backups\Test_Backup\' + SU_HOME + '\' + lcTimeStamp + ' ' + changes + "'"



Regards
Andy Kramek
Microsoft MVP (Visual FoxPro)
Tightline Computers Inc, Akron Ohio, USA



COMPLETE THREAD
directory() command Posted by bryan wetton @ 1/1/2009 1:38:18 AM
RE: directory() command Posted by Biju Thomas @ 1/1/2009 3:39:16 AM
RE: directory() command Posted by Vladimir Zografski @ 1/1/2009 2:45:37 PM
RE: directory() command Posted by mike castillo @ 1/1/2009 3:03:35 PM
RE: directory() command Posted by Vladimir Zografski @ 1/1/2009 4:30:42 PM
RE: directory() command Posted by Biju Thomas @ 1/1/2009 4:24:09 PM
RE: directory() command Posted by Jyothish KV @ 1/1/2009 1:23:25 PM
RE: directory() command Posted by Andy Kramek @ 1/1/2009 1:27:50 PM
RE: directory() command Posted by Biju Thomas @ 1/1/2009 4:29:13 PM