abby13
31st January 2009, 12:53
Hi,

I have to read file form the server in a directory.
the file name format would be:
ITM-XXXXXXX-PART-MMDDYYHHMMSS

There would be several such files on the server.
I have to pick the latest file ov the current date.(MMDDYY).

Is there any Baan function which can sort the files in the path and pick the
latest one of current date after which, i can transfer the file using server2client?

Thanks

abby13

NirajKakodkar
2nd February 2009, 06:01
As far as I know , I dont think there is a direct function which will give you the sorted list of files , but offcourse you can write you own function .

You can make use of "file.stat" get the list of files in the directory in a flat file in sort order you want and then accordingly pick the file you want .

Hope this helps .

Regards,
Niraj

NPRao
2nd February 2009, 19:11
Is there any Baan function which can sort the files in the path and pick the latest one of current date after which, i can transfer the file using server2client?
There are no ready-made functions in Baan to do this, but you are on Unix so you can use the find command options:

-atime n True if the file access time subtracted from the initialized time is n-1 to n multiples of 24 h. The initialization time shall be a time between the invocation of the find utility and the first access by that invocation of the find utility to any file specified by its path operands. The access time of directories in pathname_list is changed by find itself.

-mtime n True if the file modification time subtracted from the initialization time is n-1 to n multiples of 24 h. The initialization time shall be a time between the invocation of the find utility and the first access by that invocation of the find utility to any file specified in its path operands.

-ctime n True if the time of last change of file status information subtracted from the initialization time is n-1 to n multiples of 24 h. The initialization time shall be a time between the invocation of the find utility and the first access by that invocation of the find utility to any file specified by its path operands.

-newer file True if the current file has been modified more recently than the argument file.

sushil
3rd February 2009, 10:55
Hi,

I have had came across similar things but on windows.
i used - run.prog("command.com","/c dir *_%date:~7,2%_%date:~4,2%_%date:~10,4% " > c:\" & fname ,RP_NOWAIT)


(file was of the format xxx_03_02_2009.xxx )

i.e i used to pick the file name by today's date and place the name of the file in another file.

I assume this helps .!!

Regards,
Sushil Kumar Mudaliar

abby13
4th February 2009, 14:34
Hi All,

Thanks for the replies.

i used the find command in shell in the following way.

shell("find /export/home/users/gssapatw –name ‘*-020409*’ >fileout",0)

i am expecting the list of files in fileout which is a tmp file created using creat.tmp.dir().

However I am not getting the list.
Manually if i use this command i get the list correctly.

I am i missing something?

Thanks

abby13

NPRao
4th February 2009, 20:18
Did you test the command on a Unix terminal?
shell("find /export/home/users/gssapatw –name ‘*-020409*’ >fileout",0)
the name string should be within double or single quotes and not starting with ` (grave-accent)
Example command line usage:
find /app/lms/lmss/opt/bse/tmp -name 'tmp*08*'
or
find /app/lms/lmss/opt/bse/tmp -name "tmp*08*"

abby13
5th February 2009, 08:52
Hi ,

I tried bu changing the quotes as suggested but still i dont get the list in fileout.

ret = shell("find /export/home/users/gssapatw -name '*PEN-020409*'>fileout",0)

thanks

abby13

wiggum
5th February 2009, 11:15
Append -print to your command line to get the file names found

abby13
6th February 2009, 12:38
Hi Wiggum,

I tried print but its not working.

Regards,

abby13

grzegorz
6th February 2009, 13:47
This is what we use to process all files in a directory. You may just load filenames to memory and sort to determine the latest file.
The functions in question are:
dir.open, dir.entry, dir.close


long dir
string path(1024)
string dirent(1024)

path = ".... my path..."
dir = dir.open(path)
if dir < 0 then
*problem with path*
return
endif
while 1 | loop for all files in directory
dirent = dir.entry(dir, TFILE,
type, size, mode)
if dirent = "" then
*no more files*
break
else
*process file, filename is stored in dirent*
endif
endwhile
dir.close(dir)

Function dir.open creates a static snapshot of a directory. Files created by another process after dir.open will not be read within loop.