Recent

Author Topic: Moving a folder after a time of inactivity  (Read 476 times)

sblisesivdin

  • New Member
  • *
  • Posts: 13
Moving a folder after a time of inactivity
« 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?

GetMem

  • Hero Member
  • *****
  • Posts: 3685
Re: Moving a folder after a time of inactivity
« Reply #1 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.
« Last Edit: March 23, 2020, 12:04:21 pm by GetMem »

sblisesivdin

  • New Member
  • *
  • Posts: 13
Re: Moving a folder after a time of inactivity
« Reply #2 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.

dbannon

  • Hero Member
  • *****
  • Posts: 1069
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Moving a folder after a time of inactivity
« Reply #3 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
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

GetMem

  • Hero Member
  • *****
  • Posts: 3685
Re: Moving a folder after a time of inactivity
« Reply #4 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.
« Last Edit: March 23, 2020, 01:13:34 pm by GetMem »

dbannon

  • Hero Member
  • *****
  • Posts: 1069
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Moving a folder after a time of inactivity
« Reply #5 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
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

ASerge

  • Hero Member
  • *****
  • Posts: 1612
Re: Moving a folder after a time of inactivity
« Reply #6 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.

 

TinyPortal © 2005-2018