Perl | glob() Function
Last Updated :
12 Jun, 2019
glob() function in Perl is used to print the files present in a directory passed to it as an argument. This function can print all or the specific files whose extension has been passed to it.
Syntax: glob(Directory_name/File_type);
Parameter: path of the directory of which files are to be printed.
Returns: the list of files present in the given directory
Example 1: Printing names of all the files in the directory
@files = glob ( 'C:/Users/GeeksForGeeks/Folder/*' );
print "@files\n" ;
|
Output:
Above example will print all the files of the requested directory.
Example 2: Printing names of the specific files in the directory
@Array = glob ( 'C:/Users/GeeksForGeeks/Folder/*.txt' );
print "@Array\n" ;
|
Output:
Above example will print all the files of the requested directory that end with .txt extension.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...