tags:

views:

405

answers:

3

Hello, I am getting an error I do not understand. I am using File:Find to recurse a fylesystem on Windows using Activestate Perl 5.8.8 and trying to stat $File::Find::name; so I am not stat-ing a filename got from a text file scanning requiring chomp-ing or newline removing. I was unable to get file modification time, the mtime in:

my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($File::Find::name);

so trying a

-s $File::Find::name 

gives me the error:

Unsuccessful stat on filename containing newline

A typical file name found is F01-01-10 Num 0-00000.pdf but I get the same error even renaming in E02.pdf

+4  A: 

According to perldiag if any file operation fails and the filename happens to contain a newline character, the warning "Unsuccessful on filename containing newline" will be emitted.

The assumption is that, as you say, the filename has come from standard input or similar, and the user has forgotten to chomp the newline away. You might want to pass the string through chomp anyway, just to see if it works.

There is some evidence that &CORE::stat mtime might be broken with some combinations of OS patchlevel and ActiveState Perl versions - a suggested workaround is to use the File::stat module like so:

my $sb = stat($File::Find::name);
my $mtime = scalar localtime $sb->mtime;

...you might find File::stat's object representation to be more convenient than the list returned by CORE::stat.

rjh
A: 

Even i got the same error while trying to delete a folder. i used chomp before using rmtree command. That solved my problem.

Gayathri
A: 

Ran into this same problem in my script and found my mistake to be when i created the file i tagged a date stamp to the end and forgot to chomp my $DATE variable before adding it to the file name.

Mesa