I just got the time to do some tests with a small app of mine that cleans up several directories and temp tables.
To have a start, I extracted a function called 'CheckCleanupBatch' that generates a batch file in case it doesn't exist anymore.
Most of the VFP code is accepted, however two errors and one warning are thrown.
Error #1
XS0023 Operator '!' cannot be applied to operand of type 'ARRAY'
Code: Select all
IF NOT DIRECTORY( lcPath )
Error #2
XS0103 The name 'MKDIR' does not exist in the current context
Code: Select all
MKDIR ( lcPath )
Warning #1
XS9085 Unbalanced textmerge delimiters '<<' and '>>'.
Code: Select all
forfiles /P "%PATH1%" /S /M %FILEFILTER% /D %OLDERTHEN% /C "cmd /c del @file | echo delete @file from @fdate >> %LOGFILE%"
Well, I could replace it by '~~' or maybe '::' and later use STRTRAN() to replace them with '>>', but accepting it in the first place would be way cooler
Here comes already changed testcode. I couldn't use my original code, as is makes use of other function calls that I didn't want to test in the first place. So it is a bit stripped and some values are filled with fix paths, but for testing purposes this was more than sufficient.
Code: Select all
FUNCTION CheckCleanupBatch as Boolean
LOCAL lcPath as String, lcOutput as String
lcPath = "D:xstests_al-components"
lcOutput = "D:xstestslogfiles"
IF NOT DIRECTORY( lcPath )
TRY
MKDIR ( lcPath )
CATCH
ENDTRY
ENDIF
IF NOT FILE( lcPath + "cleanup.bat" )
LOCAL lcOutputPath as String, lcUserTemp as String, lcBatch as String
STORE "" TO lcOutputPath, lcUserTemp
lcOutputPath = PROPER( IIF( EMPTY( lcOutput ) , GETENV( "TEMP" ) , lcOutput ) )
lcUserTemp = PROPER( STRTRAN( GETENV( "TEMP" ) , LOWER( GETENV( "Username" ) ) , [%username%] ) )
lcBatch = ""
TEXT TO lcBatch TEXTMERGE NOSHOW PRETEXT 1+2
@echo off
REM ----------------------------------------
REM variable declaration
REM ----------------------------------------
set PATH1="<<JUSTPATH( ADDBS( lcOutputPath ) )>>"
set OLDERTHEN=-14
set FILEFILTER=*.*
set LOGFILE="<<PROPER( ADDBS( JUSTPATH( FULLPATH( 'cleanup.exe' ) ) ) ) >> _log%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%cleanupbatch.log"
REM ----------------------------------------
REM starting batch run
REM ----------------------------------------
echo starting batch > %LOGFILE%
echo ************************** >> %LOGFILE%
echo deleting protocol >> %LOGFILE%
REM ----------------------------------------
REM select files
REM ----------------------------------------
forfiles /P "%PATH1%" /S /M %FILEFILTER% /D %OLDERTHEN% /C "cmd /c del @file | echo loesche @file vom @fdate >> %LOGFILE%"
REM ----------------------------------------
REM end of batch run
REM ----------------------------------------
echo ************************** >> %LOGFILE%
echo end of batch run >> %LOGFILE%
ENDTEXT
TRY
STRTOFILE( lcBatch , lcPath + "cleanup.bat" , 0 )
CATCH
ENDTRY
IF FILE( lcPath + "cleanup.bat" )
STRTOFILE( STRCONV( STRCONV( SYS( 2007 , lcBatch , 1 , 1 ) , 13 ) , 15 ) , lcPath + "cleanup.crc" , 0 )
ENDIF
ENDIF
RETURN .T.
ENDFUNC