Sunday, November 7, 2010

Perl: to check wether its a file or directory


Share at Facebook

Lets say you have a list of files and folders on your hand(usually from glob() function), and now you are looking to detects whether its a file or folder. Its easy to handle from perl using (-f). For example.


$file = "text.txt";
if( (-f) $file){
print "its a file.";
}else{
print "its a folder";
}



Very simple.

By the way, if you want to check whether the file or folder exists or not, that case you can use the (-e) for exists or not on similar fashion.

have a nice day,
demon!




No comments: