Page 1 of 1

Need a little help on my archiving script

Posted: 13 Feb 2019 16:52
by rclkrtrzckr
Hi all

Haven't been here for a while, still a very very happy XYplorer user :-)

With your help, I created a little script that takes my files from a specific folder and moves them into dated subfolders:

Code: Select all

if (confirm("Archive?", , , 4)==1) { 
  $root = "D:\_inbox\";
  foreach($file, listfolder($root)) {
      $folder = $root . regexreplace(property("#date.c",$file), "^(\d+)(?:\.|-|/)(\d+)(?:\.|-|/)(\d+)(.*)", "..\_archive\$3\$2") ;

      moveto $folder, $file, , 2;

  }
 }
This works perfectly fine, but one thing is missing: It should only move files older than X days, where X should be taken from the confirmation dialog (if that's possible, otherwise hardcoded).

I have tried a few things a while ago, but I forgot what exactly. What I remember is that it didn't work :-)

Any hint highly appreciated!

Cheers

André

Re: Need a little help on my archiving script

Posted: 13 Feb 2019 17:13
by highend
The script already includes how the created date is received for each file.

So the relevant thing needed is a datediff() check...
where X should be taken from the confirmation dialog
confirm() doesn't let you enter anything, you could use input() e.g. with
a default value instead...

Re: Need a little help on my archiving script

Posted: 13 Feb 2019 19:40
by rclkrtrzckr
Awesome, thanks!

Here we go:

Code: Select all

$num = input("Archive files older than","days from today (considering modification date)",14);
    $root = "D:\_inbox\";
    foreach($file, listfolder($root)) {
      $date = property("#date.m",$file);
      $folder = $root . regexreplace($date, "^(\d+)(?:\.|-|/)(\d+)(?:\.|-|/)(\d+)(.*)", "..\_archive\$3\$2") ;

       if (datediff($date,,"d")>$num) {
          moveto $folder, $file, , 2;
	}
      }
I somehow still didn't get used to this language ;-)

Thanks again, highend!

Cheers

André