3. Sorting a directory for insertion of details into a database without using a HttpServletRequest object. |
The following code sorts a directory so that when items from the directory are retrieved they are returned in the correct order that we want to see them within some relational database. This is all done without the need of a HttpServletRequest object as can be seen. In this case we remove all directories and sort the remaining files by their last modified date and in descending order. The reasons for these requirements are irrelavent for this example but show what can easily be done with Xload. Please note that when using Xload in this configuration with an HttpServletRequest object then all paths must be absolute (which are obviously machine dependant).
XloadManager xman = new XloadManager();
XloadDirectory dir = xman.getDirectory("/data/uploaded"); dir.setOmmitDirectories(true); dir.sortBy(3, false); while(dir.hasMore()){ XloadFile file = (XloadFile)dir.getNext(); //enter details of this file into relational database. }
|
Please note the Linux/Unix/OS X notation for the absolute path given for the location of the directory.
© Gubutech(Xload) 2006 (v1.2)