How do i get filename of the most recently modified file in a directory?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • As the title says i am looking for a way to get the filename* of the most recently modified file in a directory and perhaps store it in a global string, any help would be greatly appreciated.

    Example of my folder
    C:\myfiles\file_randomstringhere.log
    C:\myfiles\file_randomstringhere.log
    C:\myfiles\file_randomstringhere.log

    ~MMF Newbie~

    Edited 3 times, last by Spryz (January 5, 2023 at 1:31 AM).

  • The basic idea is to open up a .log file into a List Object but i have no idea how to find which log file is the most recent one and i still need to figure out how to detect when that log file gets updated with new data.

    ~MMF Newbie~

    Edited once, last by Spryz (January 5, 2023 at 1:48 AM).

  • Well, you would need to loop through the files and use File-Folder object to get the date...
    But that might be a bit hard because comparing which date is newer is complicated
    So for that, in a project I've worked on, I've used TimeStamp object to turn the date got from File-Folder object into a timestamp.
    Then you can just compare the timestamps, bigger is newer.

  • * Start of Frame
    Common Dialog object: Show Open Dialog

    * Common Dialog object: Open Dialog - OK
    FileTime object : Set File GetFilename$( "Common Dialog object" )
    Counter : Set Counter to YearModified( "FileTime object" )

  • Thank you i was using FileTime with the same function but it came up 0 or -0 i will give this a try, i can do more advanced stuff i swear but i get stuck on such a simple task i feel so silly lol

    If there is an easier way my logs follow the following filenames
    BreachingChargeLog_08-01-2023_20-00-43.txt
    BreachingChargeLog_03-01-2023_11-00-40.txt

    ~MMF Newbie~

    Edited once, last by Spryz (January 9, 2023 at 7:23 PM).

  • Well there are always different ways of doing things. The String Parser extension, for example, allows you to TAKE strings apart and put them back together. However, I do not know what your application is to do or what the filename is telling you or means. I am unsure what you mean by "easier way". Are you talking PROCESSING speed, QUICK sorting, SQL database FUNCTIONS ect... It ALSO depends on what platforms you are WANTING TO SUPPORT. I know what you mean by feeling silly with a simple task sometime times. The more you work with Fusion the easier it becomes. There are a lot smarter people out there than me but I hope this helps a little.

  • I managed a super easy way around this by having my app create a .bat script and run it to copy the latest file over and delete the .bat script afterwards.

    Thank you all for your time, sorry i didnt give out more information i usually dont ask for help.

    ~MMF Newbie~

    Edited 2 times, last by Spryz (January 10, 2023 at 9:27 PM).

  • Yes thats why I was asking what OS you wanted to support. You may have to create a command line depending on the OS you are supporting and what info you need based on your design. Also remote support comes into play, Glad you found a solution.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!