• Python Script

    From Schinken@46:1/700 to All on Wed Dec 6 15:58:42 2017
    Hello there,

    I was wondering how to write a script in python that displays
    the last changed file from a directory.

    If someone have a tip, please tell me, if not have a good day :)
    --- SBBSecho 3.03-Linux
    * Origin: thePharcyde_ telnet://bbs.pharcyde.org (Wisconsin) (46:1/700)
  • From DaiTengu@46:1/193 to Schinken on Wed Dec 6 17:04:55 2017
    Re: Python Script
    By: Schinken to All on Wed Dec 06 2017 03:58 pm


    Hello there,

    I was wondering how to write a script in python that displays
    the last changed file from a directory.

    Does it _HAVE_ to be in Python? Because it's a one-liner in Bash :)

    In Python though, you'd probably have to loop over all the files using os.listdir() and use os.path.getmtime() to get the time on each object (it returns the time via unix timestamp).

    I'm not the world's best python guy, or even the world's most medicore, so there may be a better way to do it, but that's just off the top of my head.

    DaiTengu

    ... A dog is the only thing on earth that loves you more than you love yourself.
    --- SBBSecho 3.03-Linux
    * Origin: The Sport is War, Total War - warensemble.com (46:1/193)
  • From Accession@46:1/100 to Schinken on Wed Dec 6 17:05:38 2017
    Hello Schinken,

    On Wed Dec 06 2017 15:58:42, Schinken wrote to All:

    I was wondering how to write a script in python that displays
    the last changed file from a directory.

    If someone have a tip, please tell me, if not have a good day :)

    While I'm not very versed in Python, I consider myself somewhat a pro at Google. ;)

    You could try here:

    https://stackoverflow.com/questions/24134495/python-get-most-recent-file-in-a-directory-with-certain-extension

    Or:

    https://stackoverflow.com/questions/5566310/how-to-recursively-find-and-list-the-last-modified-files-in-a-directory-with-s

    Hope that helps, if not.. hopefully a python guru can help you out. ;)

    Regards,
    Nick

    ... "Не знаю. Я здесь только работаю."
    --- GoldED+/LNX 1.1.5-b20170303
    * Origin: thePharcyde_ distribution system (Wisconsin) (46:1/100)
  • From Schinken@46:1/700 to DaiTengu on Thu Dec 7 08:01:38 2017
    Re: Python Script
    By: DaiTengu to Schinken on Wed Dec 06 2017 05:04 pm

    Hello DaiTengu,

    thanks for the answer!
    No it don't have to be in python.

    A bash oneliner sounds pretty good. Could you write me the oneliner? :)

    Good day and greetings

    Schinken
    --- SBBSecho 3.03-Linux
    * Origin: thePharcyde_ telnet://bbs.pharcyde.org (Wisconsin) (46:1/700)
  • From Schinken@46:1/700 to Accession on Thu Dec 7 08:05:10 2017
    Re: Python Script
    By: Accession to Schinken on Wed Dec 06 2017 05:05 pm

    Hello Nick,

    I will check these links out.

    Thankyou for using your pro Google skills to help me :)

    Have a nice day

    Schinken
    --- SBBSecho 3.03-Linux
    * Origin: thePharcyde_ telnet://bbs.pharcyde.org (Wisconsin) (46:1/700)
  • From Accession@46:1/100 to Schinken on Thu Dec 7 16:17:06 2017
    Hello Schinken,

    On Thu Dec 07 2017 08:05:10, Schinken wrote to Accession:

    I will check these links out.

    Thankyou for using your pro Google skills to help me :)

    Otherwise, since you mentioned bash would be okay, try this:

    find . -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "

    One line, in case it wraps.

    Regards,
    Nick

    ... "Не знаю. Я здесь только работаю."
    --- GoldED+/LNX 1.1.5-b20170303
    * Origin: thePharcyde_ distribution system (Wisconsin) (46:1/100)
  • From DaiTengu@46:1/193 to Schinken on Thu Dec 7 17:01:36 2017
    Re: Python Script
    By: Schinken to DaiTengu on Thu Dec 07 2017 08:01 am

    thanks for the answer!
    No it don't have to be in python.

    A bash oneliner sounds pretty good. Could you write me the oneliner? :)

    It depends upon how you want to go about it. if it is a flat directory, with no subdirectories:

    ls -altr /path/to/dir | tail -n 1

    if you have subdirectories:

    find /path/to/dir -type f | xargs ls -altr | tail -n 1

    If you just want the file name, and not the ownership/modification time/modes, change "ls -altr" to "ls -tr" in any of the above.

    DaiTengu

    ... A man's only as old as the woman he feels.
    --- SBBSecho 3.03-Linux
    * Origin: The Sport is War, Total War - warensemble.com (46:1/193)