Problem solve Get help with specific problems with your technologies, process and projects.

Cleaning up unused or temporary IFS files -- Part 1

Deleting object in the IFS is a simple process. However, there is no mechanism on the iSeries that allows you to selectively delete IFS files based on certain criteria, such as the file type or the number of days the file has been unused. What do you do then? You have to create your own command. In part 1 of this series Ron Turull walks you through the first step of creating the command.


Ron Turull

Much of the Integrated File System (IFS) operates as a sort of mixture of DOS, UNIX and OS/400 (i5/OS). The Work...

with Object Links (WRKLNK) command is reminiscent of the DOS DIR command, although the concept and mechanics of "hard" and "symbolic" links come directly from UNIX. The object types (e.g., directories, stream files, sockets, etc.) and the way they are accessed programmatically are characteristic of both DOS and UNIX. Then there are the peculiarities of the IFS that would have to be attributed to the influences of IBM and OS/400. All in all, it is not a bad system -- just a little quirky with its multiple personalities.

One influence from the common-sense arena that unfortunately did not make it into the IFS is the use of selective deletion. Actually, OS/400 has a type of selective deletion. You can delete objects by type only by specifying the corresponding delete command. For example, to delete a file you must use the DLTF command, to delete a program you use the DLTPGM command, and so forth.

Deleting IFS files
Deleting objects in the IFS is a simpler process: You use the Remove Link (RMVLNK) command from OS/400-i5/OS. You can also delete objects in the IFS from other systems, like an attached PC using Windows Explorer. However, there is no mechanism on the iSeries that allows you to selectively delete IFS files based on certain criteria, such as the file type or, in the example we'll be discussing, the number of days the file has been unused.

More Information

Some applications and utilities make ample use of the IFS for temporary files. You may find it efficient to have a way to automatically delete those temporary files. For example, you may want to delete a file if it has not been used for, say, at least 15 days. A command like the following would do the trick:

DELIFSFILE PATH('/tmp/*.dta') DAYSUNUSED(15)

Such a command does not exist, so we will have make our own.

Developing a DELIFSFILE utility
The code for the command interface portion of our utility is shown below.

             CMD        PROMPT('Delete IFS Files')
             PARM       KWD(PATH) TYPE(*PNAME) MIN(1) PROMPT('Path +
                          to files (wildcards OK)')
             PARM       KWD(DAYSUNUSED) TYPE(*INT4) SPCVAL((*NONE +
                          0)) MIN(1) PROMPT('Days unused')

Specify "DELIFSFILE" as the command processing program (CPP) when you compile the command.

The CPP for the DELIFSFILE command can be found here.

As indicated before, its name is also DELIFSFILE.

Probably the first thing you will notice is that the code is in C. For many years, I have encouraged AS/400-iSeries professionals to get to know the C language. For many endeavors, C is a far superior language -- in both ease of coding and efficiency of the final program -- than any of the other languages on the iSeries.

In years past, even though I had encouraged readers to learn C, I had refrained from publishing code in C so readers would not be forced to buy the C compiler. But ILE C/400 has been shipping as part of OS/400-i5/OS since V5R1, so most users now have the C compiler available. (ILE C/400 also comes with WebSphere, but that's another story.)

The program uses the Qp0lGetAttr API to retrieve the usage attributes for the files in the IFS. This API requires some fairly complex data structure programming and is the main reason the C language is employed. (C's programming mechanisms for defining and manipulating data structures are simply the best.)

We will discuss the code in detail in the next installment of this article. Until then, you may want to familiarize yourself with the Qp0lGetAttr API.

-----------------------------------
About the author: Ron Turull is editor of Inside Version 5. He has more than 20 years' experience programming for and managing AS/400-iSeries systems.


Dig Deeper on Integrated File System (IFS)

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close