CodeQuestor
CodeQuestor

Reputation: 911

How to change the mtime of the directory and its files in perl?

I want to change the modification time (mtime) of the directory and all its files recursively. I tried this -

utime(undef, 1396396800, "/X/Y/dir1");

dir1 contains more directories and files, the above statement only changing the mtime of /X/Y/dir1 only , not other directories/files inside /X/Y/dir1.

Is there any method wich can recursively change the mtime of directory in the perl?

Upvotes: 2

Views: 538

Answers (1)

Sobrique
Sobrique

Reputation: 53478

There is no "recursively change mtime" function. You'll have to implement it yourself with File::Find.

Something like this:

#!/usr/bin/env perl
use strict;
use warnings;

use File::Find;

sub change_mtime {
    utime( undef, 1396396800, $File::Find::name );
}

find( \&change_mtime, "/X/Y/dir1" );

(I'm assuming your utime example is correct, I haven't tested it)

Upvotes: 6

Related Questions