Page 1 of 1
Delete files by date
Posted: Sun Jul 10, 2022 4:27 pm
by franco
I am trying to delete all .mem files in a folder where filedate() is less then date() - 20
I do not know the name of the files. I can delete them if I know the name of the file.
mem is a folder in the current path.
Code: Select all
local ti := 20
? delete file for filedate('mem\*.mem') < ti
? erase for filedate('mem\*.mem') < ti
Thanks, Franco
Re: Delete files by date
Posted: Sun Jul 10, 2022 4:44 pm
by AUGE_OHR
hi,
try this
Code: Select all
#include "Directry.ch"
PROCEDURE TESTDEL(cDate)
LOCAL dDate
LOCAL aDir := DIRECTORY("*.MEM")
ASORT(aDir,,, {|aX,aY| aX[F_DATE] > aY[F_DATE] }
nMax := LEN(aDir)
FOR n := nMax TO 1 STEP -1
dDate := aDir[i][F_DATE]
IF dDate <= CTOD(cDate)
FERASE( Dir[i][F_NAME]
ELSE
EXIT
ENDIF
NEXT
Re: Delete files by date
Posted: Sun Jul 10, 2022 5:14 pm
by franco
Thanks, Jimmy
the first characters of file name are a date. How could i use that instead if file date like.
filename is 0707202211002.mem this is a date, a time, and a column number with no separators.
Code: Select all
Ddate := aDir[i] [ ctod(substr([F_DATE],1,8)
This way I could erase from the original date. In my scheduler program the system date changes when I edit a mem file.
Re: Delete files by date
Posted: Sun Jul 10, 2022 5:32 pm
by AUGE_OHR
hi Franco,
your Filename is "bad" to ASORT()
try this
Code: Select all
cFile := aDir[i][F_NAME]
IF File2Date(cFile) <= CTOD(cDate)
FERASE( Dir[i][F_NAME]
FUNCTION File2Date(cFile)
LOCAL cDay, cMonth, cYear
cDay := SUBSTR(cFile,1,2)
cMonth := SUBSTR(cFile,3,2)
cYear := SUBSTR(cFile,5,4)
RETURN StoD(cYear + cMonth + cDay)
Re: Delete files by date
Posted: Sun Jul 10, 2022 6:46 pm
by franco
I will try and let you know. You give me so may new ideas from your programming knowledge.
Tied up for rest of day.
You got me thinking. I have a field in table that is create date of record.
It would be easy to go though file and if field date is less then ? create file name and delete it.
Re: Delete files by date
Posted: Sat Jul 16, 2022 4:24 pm
by franco
Hi Jimmy
The following seems to work fine.
I just keep looping though the file.
This works better because I am using a field with original date. If using system date it changes with each modification of record.
Code: Select all
SET DATE FORMAT TO 'ddmmyyyy'
fi2 := dtoc(date) //+fi1+alltrim(str(tim))
SET DATE FORMAT TO 'dd/mm/yyyy'
fi := 'Appmem\'+fi2+fi1+alltrim(str(tim))+'.mem'
if file(fi)
erase (fi)
endif