Sunday, November 7, 2010

Perl: to check wether its a file or directory

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.";
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,

No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...