Lazarus

Programming => Operating Systems => Windows => Topic started by: sblisesivdin on March 23, 2020, 11:36:31 am

Title: Moving a folder after a time of inactivity
Post by: sblisesivdin on March 23, 2020, 11:36:31 am
Hello dear all,

I am trying to write a small program controlling my scientific calculations. I can add, copy remove files and folders with controlling many things. However, I need to control a folder with files and when any of the files are not accessed (mostly accessed for writing) for a while (for example 30mins) I want to move the files to another folder.

The thing is how can I filter the folder for inactivity?
Title: Re: Moving a folder after a time of inactivity
Post by: GetMem on March 23, 2020, 11:58:58 am
@sblisesivdin

Create a hash list with all the files in the folder, when a particular file changes the hash will also change. All you have to do is compare two hash lists from time to time. Use the TFPHashList from contnrs.
Title: Re: Moving a folder after a time of inactivity
Post by: sblisesivdin on March 23, 2020, 12:27:37 pm
Thank you for this very good idea. I stuck with classical folder operations and this is what I am searching for.
Title: Re: Moving a folder after a time of inactivity
Post by: dbannon on March 23, 2020, 12:33:19 pm
sblisesivdin,  I note you say "mostly accessed for writing", if that "mostly" means you also need to be aware of another process reading, its a bit hard. Reading won't change the hash for example.

Important question - what operating system are you using ?  On linux, you can check the atime of all the files, would be a very fast process, that would tell you if the files had been written to or read.  On almost all systems, atime is enabled by default.  I expect (but don't know for sure) that MacOS will also provide atime.

I am no windows expert but I believe NTFS does not offer atime.  Almost impossible to tell if the file has been read.  I think....

Davo
Title: Re: Moving a folder after a time of inactivity
Post by: GetMem on March 23, 2020, 12:40:07 pm
Quote
Thank you for this very good idea. I stuck with classical folder operations and this is what I am searching for.
Once a forum user asked for an application which compares two folders, then list the same files. I know it's not exactly what are you after, but is not to different either. Please download and test attached project.
Title: Re: Moving a folder after a time of inactivity
Post by: dbannon on March 23, 2020, 12:48:54 pm
Actually, looks like I am wrong, NTFS does have an atime attribute now.

Reading that attribute would be a lot faster than reading all of all the files to generate a hash.

Davo
Title: Re: Moving a folder after a time of inactivity
Post by: ASerge on March 23, 2020, 09:02:27 pm
Hello dear all,

I am trying to write a small program controlling my scientific calculations. I can add, copy remove files and folders with controlling many things. However, I need to control a folder with files and when any of the files are not accessed (mostly accessed for writing) for a while (for example 30mins) I want to move the files to another folder.

The thing is how can I filter the folder for inactivity?

See Watching a folder for changes with DirWatch (https://forum.lazarus.freepascal.org/index.php/topic,46255.msg334820.html#msg334820).
TinyPortal © 2005-2018