> 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