ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

QShell List Command Date Format Anomaly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • QShell List Command Date Format Anomaly

    I have written an RPGLE program that deletes files in certain IFS folders that are older than a given date (the retention period for each folder is held in a control file).

    For each folder it uses the QShell LS (List) command as below to list all files, sorted by last modified date and outputting to a file:

    Code:
    STRQSH CMD('ls -ltr /foldername >/qsys.lib/DATALIBR.lib/prgifswkfi.file/prgifswkfi.mbr')
    The result looks like below:

    Code:
    -rwxrwxrwx  1 FOWNER  0                343990 Jul 14  2022 20220714.txt
    -rwxrwxrwx  1 FOWNER  0                243145 Jul 15  2022 20220715.txt
    -rwxrwxrwx  1 FOWNER  0                 60576 Jul 16  2022 20220716.txt
    -rwxrwxrwx  1 FOWNER  0                 18959 Jul 17  2022 20220717.txt
    -rwxrwxrwx  1 FOWNER  0                388469 Jul 18 20:41 20220718.txt
    -rwxrwxrwx  1 FOWNER  0                340068 Jul 19 21:45 20220719.txt
    -rwxrwxrwx  1 FOWNER  0                285709 Jul 20 17:53 20220720.txt
    -rwxrwxrwx  1 FOWNER  0                287966 Jul 21 21:56 20220721.txt​
    I know the date columns vary depending on the length of the owner names and I have extracted the date and filename with no problem until now.
    As far as I was aware during my testing, the date format shows as Month + Day + Year if the file is for a previous year and Month + Day + Time if it's for the current year.

    In test, everything worked fine, but in this folder there is something weird going on.
    Prior to 18th July 2022 the files show correctly with the year, but from the 18th onwards they all show the timestamp, so my date formatting assumes that this is 2023 not 2022.

    This is totally unexpected. Is there something maybe I am not aware of with the List command and the way it outputs the dates?
    We are running on A7.1 (in the process of undating to A7.3) so it might possibly be a bug?

    Yes I know I could have written this differently, but some folders have hundreds of temporary files in them and we want an audit process.
    Using the List command I can retrieve a list of the files in 1 single folder by date and when I come to one that has a more recent date than the cutoff, I ignore the rest of the files.
    Poddys Rambles On

  • #2
    I'm kind of answering my own question in a way but I just found something that does give a kind of logical reason for my problem:
    The article is: https://www.tek-tips.com/viewthread.cfm?qid=880768 and the relevant paragraph is:

    "If the time of last modification is greater than six months ago, the time field is shown in the format month date year where as files modified within six months the time field is shown as month date time format".

    If that is indeed the problem, looks like I need to tweak my function that converts the LS output to an ISO date, so if the time is shown it uses the month to determine if it's current or last year.
    Poddys Rambles On

    Comment


    • Poddys
      Poddys commented
      Editing a comment
      This does indeed seem to be the case and my logic of using the fact that if the time was output, use the current year needs to be modified to:

      If the time is output, if the numeric value of the month if greater than the current month, set the year to last year, else current year.

      So, if in January (month 01) we have a date with a month of Aug (08), that must be last year. As only the last 6 months will show a time and older dates will show the year, shouldn't be any confusion over the which year.

      Ok to mark this as closed, I can't see an option.

  • #3
    For more consistency, you have two options that I can think of.

    1) Use the APIs opendir(), readir() and stat() to process the entries in a directory and then unlink() any files that meet your criteria.

    2) Use the new IFS facilities in SQL to process the directory. That would let you use a simple WHERE clause to list only the files that match your criteria and then delete those.

    Comment

    Working...
    X