DEFINE VARIABLE cDir AS CHARACTER NO-UNDO initial '/home/raj/'.
define temp-table tt-file
field tfile as char format "x(22)".
define variable vfile as char format "x(22)" no-undo.
INPUT FROM OS-DIR (cDir) ECHO.
REPEAT:
create tt-file.
IMPORT tt-file.tfile.
FILE-INFO:FILE-NAME = cDir + tt-file.tfile.
if file-info:file-name begins cdir + "RATES"
and string(month(file-info:file-mod-date)) = string(month(today)) THEN
DISPLAY tt-file.tfile FORMAT "X(22)" LABEL 'name of the file'
FILE-INFO:FULL-PATHNAME FORMAT "X(21)" LABEL 'FULL-PATHNAME'
FILE-INFO:PATHNAME FORMAT "X(30)" LABEL 'PATHNAME'
FILE-INFO:FILE-TYPE FORMAT "X(5)" LABEL 'FILE-TYPE'
file-info:file-mod-date.
end.
我遇到的问题是我当前有多个文件,但我需要获取本月的最新文件。
答案 0 :(得分:3)
为什么不为文件创建添加两个字段:date&时间?然后,您可以轻松编写一个简单的WHERE子句,使您获得两个日期之间的最后一个文件。
DEFINE VARIABLE cDir AS CHARACTER NO-UNDO INITIAL '/home/raj/'.
DEFINE TEMP-TABLE tt-file NO-UNDO
FIELD tfile AS CHARACTER FORMAT "x(22)"
FIELD createDate AS DATE
FIELD createTime AS INTEGER.
INPUT FROM OS-DIR (cDir).
REPEAT:
CREATE tt-file.
IMPORT tt-file.tfile.
FILE-INFO:FILE-NAME = cDir + tt-file.tfile.
ASSIGN
tt-file.createDate = FILE-INFO:FILE-CREATE-DATE
tt-file.createtime = FILE-INFO:FILE-CREATE-TIME.
END.
/* Here you could add any logic to get your file */
FOR EACH tt-file NO-LOCK BY tt-file.createDate BY tt-file.createtime:
DISP tt-file.
END.
/* Updated example for doing things only with .csv files */
FOR EACH tt-file NO-LOCK WHERE tt-file.tfile MATCHES "*csv"
BY tt-file.createDate
BY tt-file.createtime:
DISP tt-file.
END.
根据您的应用程序,您可能希望使用FILE-MOD-DATE&反而是FILE-MOD-TIME。
答案 1 :(得分:0)
您的示例显示您正在使用unix / linux。你可以使用os-command
define variable cDir as character no-undo form "x(65)" initial '/home/raj/'.
define variable cFileName as character no-undo form "x(65)".
input through value(substitute("ls -1t &1", cDir)).
repeat:
import unformatted cFileName.
display cFileName.
/* if .... then */ leave.
end.
您还可以处理ls
命令的结果,而不是find
。这将需要更多的代码,但功能更强大。