Reading sorted files in a directory

squonk

squonk

Member
Hi all, I have a problem with a C BSFN thats reads certain TXT files in a particular directory, process them and move them to another as a backup.
There's no problem about all that 'cause evereything is working perfectly, but now our customer wants the process to be able to read the files in certain order, by date of modification, ascending, meaning that the first file has to be the oldest.
I haven't found anything in C about sorting files in a folder. In addition, the BSFN has to be able to work with both AS400/Unix and Windows server environments.
I would apreciate very much if anyone can help me. I don't even know for sure if its possible to do it.
Thanks a lot!
 
Diego,

I would let the operating system do the work. Using the business functions ExecuteExternalProgram (B34A1030) and GetAuditInfo (B9800100) in conjunction with the F00960 (Machine/Group Identification) you can produce a flat/text file containing the sorted filenames that can be used for further processing. Use GetAuditInfo to get the name of the host on which the process is running. Lookup/fetch the host type (UDC H90/HT) using the host name from F00960 to determine the type of host on which the process is running. Depending on the host type uses ExecuteExternalProgram to get the operating system to create the flat/text file containing the sorted filenames.
 
Diego,

This is certainly possible, just a little more complicated. You'll have to research the different O/S functions for file finding/directory searching and separate the code based on #define(d) operating system.

If the functions won't sort the returned files, you'll need to store in an array/list and sort them yourself.

Sounds like a fun project
grin.gif


Craig
 
Craig, tranks for the help. You option is the one I'm programming now.
I've created an array that holds the name and de date/time of the file. The date and the time are retrieved using Windows/Unix apis and I sort the array myself and proccess the files in order. So far so good...
Thx!
 
Hi deigo - Were you able to create this func? I am in need for a similar func. help is highly appreciated.
 
Kumar,
I don't actually have the code right now but I can get it for you once my client allow me to connect to them and make a backup of the object.
I'll let you know when I have it.
Best regards,
 
Back
Top