views:

166

answers:

1

Hello,

I have a program which requires the path to various files. The files live in different folders and are constantly updated, at irregular intervals.

When the files are updated, they change name, so, for instance, in the folder dir1 I have fv01 and fv02. Later on the day someone adds fv02_v1; the day after someone adds fv03 and so on. In other words, I always have an updated file but with different name.

I want to create a symbolic link in my "run" folder to these files, such that said link always points to the latest file created.

I can do this in Python or Bash, but I was wondering what is out there, as this is hardly an uncommon problem.

How would you go about it?

Thank you.

Juan

PS. My operating system is Linux. I currently have a simple daemon (Python) that looks every once in a while (refreshes every minute) for the latest file. Seems kind of an overkill to me.

+3  A: 

Unless there is some compelling reason that you have left unstated (e.g. thousands of files in the directory) just do it the way you suggest with a script sorting the files by modification time. There is no secret method that I am aware of.

You could write a daemon using inotify to monitor your directories and immediately set your links but that seems like overkill.

Edit: I just saw your edit. Since you have the daemon already, inotify might not be such a bad idea. It would be somewhat more efficient than constantly querying since the OS will tell you when something in your directories has changed.

I don't know python well enough to point you to anything specific but there must exist a wrapper for inotify.

Duck
Thank you, Duck. I was finally unable to use `inotify` for `libc` version reasons, but you put me on a good way to provide a much more general solution when we finally upgrade. Just for the record, there is a Python inotify module. Thanks again! (+1 and accepted)
Arrieta