Need a little help on my archiving script

Discuss and share scripts and script files...
Post Reply
rclkrtrzckr
Posts: 65
Joined: 03 Jan 2017 13:10
Location: Zurich, Switzerland

Need a little help on my archiving script

Post 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é

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Need a little help on my archiving script

Post 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...
One of my scripts helped you out? Please donate via Paypal

rclkrtrzckr
Posts: 65
Joined: 03 Jan 2017 13:10
Location: Zurich, Switzerland

Re: Need a little help on my archiving script

Post 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é

Post Reply