Midrange News for the IBM i Community


Posted by: Chris Proctor
Programmer Analyst
Columbia Sports Company
Portland, OR
RPG pgm to clean-up old files in the IFS
has no ratings.
Published: 11 Oct 2012
Revised: 23 Jan 2013 - 1706 days ago
Last viewed on: 25 Sep 2017 (5955 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

RPG pgm to clean-up old files in the IFS Published by: Chris Proctor on 11 Oct 2012 view comments(11)

Good morning. We're trying to clean-up our IFS and the users have said that they only need a 60 day retention period, so now I have to come up with an application to look at multiple folders in QDLS and delete files that are older than 60 days.

I've heard there is an API that I can use to read the files within a folder. I don't know what it is or if it will give me the creation date of the file so that I can perform an UNLINK for it.

Does anyone know what the API is called and if it would provide me with this info?

Thanks!

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: chrisp
Premium member *
Portland, OR
Comment on: RPG pgm to clean-up old files in the IFS
Posted: 4 years 11 months 15 days 1 hours 59 minutes ago

Hello all. I may have figured it out. In Scott Klements IFS book he talks about "READDIR". I'm going to give it a try and see if that works.

Gracias!

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: RPG pgm to clean-up old files in the IFS
Posted: 4 years 11 months 15 days 38 minutes ago
Edited: Thu, 11 Oct, 2012 at 13:07:28 (1810 days ago)

I wrote a Delete Old IFS file command a while back and published the code. Don't recall if it was PENTON or elsewhere. It uses the openDir, readDir, closeDir IFS APIs. If you have COZTOOLS, you can call the ifsGetDir() function and get a list of file names in an IFS directory, inspect the creation dates and then delete the "old ones". It uses these APIs under the covers.

Not certain if these APIs work with QDLS though... haven't used that folder in decades.

Posted by: chrisp
Premium member *
Portland, OR
Comment on: RPG pgm to clean-up old files in the IFS
Posted: 4 years 11 months 15 days 26 minutes ago

Hi Bob. Yeah, I have a process that uses those same functions; however, I want it to drive off a control file that contains all the folders that are to be cleaned, but I can't figure out how o make it work, because the opendir command wants a value for the folder name and I'm trying to use a field value from the control file. The parms look like this:

 

d opendir pr*extproc('opendir')

 

d dirname *value options(*string)

Any idea as to howI could change it to receive a variable name?

Thanks!

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: RPG pgm to clean-up old files in the IFS
Posted: 4 years 11 months 14 days 23 hours 53 minutes ago
Edited: Thu, 11 Oct, 2012 at 13:53:18 (1810 days ago)

You can pass a field name. Also add OPTIONS(*STRING:*TRIM) to the dirname parm so that trailing blanks are auto-removed.

 hDir = openDir( myDirVariable );

.....D openDir         PR              *   extProc(*CWIDEN :'opendir')
     D  szPath                         *   Value OPTIONS(*STRING:*TRIM) 

 

Posted by: chrisp
Premium member *
Portland, OR
Comment on: RPG pgm to clean-up old files in the IFS
Posted: 4 years 11 months 14 days 22 hours 34 minutes ago

Thanks, Bob. That worked. Now I have to figure out the whole Qp0lGetAttr mess in order to get the creation date of files. You would think by now IBM would have a simple way of doing this! Lol

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: RPG pgm to clean-up old files in the IFS
Posted: 4 years 11 months 14 days 21 hours 31 minutes ago
Edited: Thu, 11 Oct, 2012 at 16:14:41 (1810 days ago)

They do have a simpler way, it's called COZTOOLS.

Maybe I should change my slogan from:

"Providing the solutions"

to

"If you had COZTOOLS, you'd be done by now."

Posted by: Ringer
Premium member *
Comment on: RPG pgm to clean-up old files in the IFS
Posted: 4 years 11 months 14 days 15 hours 54 minutes ago

In a CLLE, redirect a STRQSH find to a QTEMP PF and read that PF, RMVLNK each file.

find '/dir/dir2' -type f -name 'MYFILE*.*' -atime +60

-atime is last access time in days. -mtime is last maintained (or created) time in days.

I prefer to use -atime. The directory names are NOT case senstive, but the FiLe NaMeS are.

Warning (or good news?), this searches sub-directories too. If you don't want to purge from sub-directores, search for a / after your directory path in each record. If you find one, it's a file in a sub-directory. If you want to keep a found file, make sure you mark it as CHGATR *READONLY *YES before your program ever runs.

Chris

Posted by: Paulster
Premium member *
Sweden and The Netherlands
Comment on: RPG pgm to clean-up old files in the IFS
Posted: 4 years 11 months 14 days 13 hours 46 minutes ago

Since we only have some folders that must be cleared, we use QSHELL for each folder:

 /* 'find &PATH  -type f -mtime +&DAYS | xargs rm' */  
 CHGVAR     VAR(&CMD) VALUE('find' *BCAT &wPATH *TCAT ' +
              -type f -mtime +' *CAT &wDAYS *BCAT '| +  
              xargs rm')                               
 STRQSH     CMD(&CMD)                                  

Posted by: Ringer
Premium member *
Comment on: RPG pgm to clean-up old files in the IFS
Posted: 4 years 11 months 14 days 5 hours 27 minutes ago
Edited: Fri, 12 Oct, 2012 at 08:33:24 (1809 days ago)

Paulster,

That 'find' syntax will fail if a large number of files are to be purged, on V5R4 anyway. With that syntax, QSHELL builds an intermediate list of the matching files it finds. In my testing a few months ago, if the list size is over about 3 Meg, QSHELL dies with the error "qsh: 001-0085 Too many arguments specified on command.".

Plus, using xargs submits a new job for every single delete, not as efficient as redirecting to a PF and RMVLNK in a RCVF loop, in one job. Just FYI. If the list is "small", should not be a problem.

Well... it depends too on what is in &WPATH. If /dir1/*.* (some file pattern) then could get the qsh: error and this option does not search sub-dirs.  If just /dir then is probably ok but this searches sub-dirs too.  Cheers. 

Chris Ringer

Posted by: Paulster
Premium member *
Sweden and The Netherlands
Comment on: RPG pgm to clean-up old files in the IFS
Posted: 4 years 11 months 14 days 3 hours 42 minutes ago

Cheers for the info Chris,

As said, I target specific folders that, up to now, do no contain a lot of files. However, this number of files will change within the year so I may have to revise the chosen strategy. 

Rgrds and have a nice weekend,

Paulster

Posted by: clbirk
Premium member *
Comment on: RPG pgm to clean-up old files in the IFS
Posted: 4 years 11 months 13 days 22 hours 15 minutes ago

Here are some ways:

1. DOT NET

Write a simple dot net program, share it to a pc as a mapped drive and let dot net do the work for you. I have a file system where we have folders (which change) and so I do it in a bat sort of like:

 

c:\makebat.exe  f:\myfolders

c:\deleteold.bat

 

The first step takes the "myfolders" and finds all the folders and creates the bat with a job that will take each folder and do the deletes of the files that qualify.

 

2. Use Bob's tool.

 

3. Go to easy400.net and get his free ifstool which has a readdir which provides you back a list, to which then you could read and create the rmvlnk commands,.

 

4. If not alot of directories, open each in inav, sort them by date, highlight first and highlight the last one you want and press delete.

 

5. Utilize the ifs commands that scott klement talks about in an rpg job.

 

6. QSHELL/QPTERM