---
title: "perl faq 学习之递归遍历目录"
author: "zhouzhao21"
date: "2009-05-05T00:16:09Z"
tags: []
categories: ["企业架构"]
slug: "perl-faq"
draft: false
lastmod: "2009-05-05T00:16:09Z"
id: 379282
url: "https://kyo-cc.iteye.com/blog/379282"
---

目的：遍历目录。

```perl

#!/usr/bin/perl
use warnings;

use File::Find;

@directories = (".", "path2traverse");
# 递归遍历指定目录（@directories），并在回调函数（wanted）中处理。
find(\&wanted, @directories);

sub wanted{
	# $File::Find::dir  is the current directory name,
	# $_ is the current filename within that directory
	# $File::Find::name is the complete pathname to the file. 
	print "full path is $File::Find::name, filename is $_\n";
}

```



原文：
<http://faq.perl.org/perlfaq5.html#How_do_I_traverse_a_>

更多：
<http://perldoc.perl.org/File/Find.html>