<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mihalytch personal blog &#187; chmod</title>
	<atom:link href="http://mihalytch.org.ua/tag/chmod/feed" rel="self" type="application/rss+xml" />
	<link>http://mihalytch.org.ua</link>
	<description>Все о высоких технологиях</description>
	<lastBuildDate>Mon, 05 Dec 2011 16:05:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Получаем список всех вложеных файлов и папок на php</title>
		<link>http://mihalytch.org.ua/programming/php/recursive-reading-files-on-php.html</link>
		<comments>http://mihalytch.org.ua/programming/php/recursive-reading-files-on-php.html#comments</comments>
		<pubDate>Tue, 18 Nov 2008 10:12:17 +0000</pubDate>
		<dc:creator>mihal</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[chmod]]></category>

		<guid isPermaLink="false">http://mihalytch.org.ua/programming/php/recursive-reading-files-on-php.html</guid>
		<description><![CDATA[Начнем как всегда с постановки задачи. Нам необходимо получить список всех вложенных директорий и файлов, находящихся в конкретной папке, и [...]]]></description>
			<content:encoded><![CDATA[<p>Начнем как всегда с постановки задачи. Нам необходимо получить список всех вложенных директорий и файлов, находящихся в конкретной папке, и выполнить некоторые действия над ними. Для этого напишем функцию, которая будет получать список всех файлов и папок, отделять эти две категории, обрабатывать отдельно и в случае нахождения вложенных папок будет вызывать себя рекурсивно.<span id="more-67"></span></p>
<p>В нижеприведенном примере мы будем выполнять действия над вложенными объектами текущей папки, присваивать всем файлам права на чтение/запись/выполнение &#8211; 666, а папкам &#8211; 777 и выводить их список на экран.</p>
<pre class="brush: php; title: ; notranslate">
function rdir ($path2dir) {
    $d = dir ($path2dir);  

    while (false !== ($entry = $d-&gt;read())) {  

        if ($entry!='.' &amp;&amp; $entry!='..' &amp;&amp; $entry!='' ) {
            $all_path = $path2dir.$entry;
            $new_path = go ($all_path, is_file($all_path));  

            if (!is_file($all_path)) {
                if (!rdir ($new_path)) {
                    return false;
                }
            }
        }
    }  

    return true;
}

function go ($path2file, $is_file = true) {  

    if ($is_file) {  

        # выполняем операцию над файлом
        # выведем относительный путь к обрабатываемому файлу
        echo $path2file,&quot;\n&quot;;  

        # установим необходимые права на файл
        if (!chmod($path2file,0666)) {
            return false;
        }  

    } else {  

        # выполняем операцию над папкой
        $path2file = $path2file.'/';  

        # выведем относительный путь к обрабатываемой директории
        echo &quot;\n\n&quot;,$path2file,&quot;\n&quot;;  

        # установим необходимые права на папку
        if (!chmod($path2dir,0777)) {
            return false;
        }
    }  

    return $path2file;
}

# начинаем с текущей папки
$folder = './';  

# непосредственно вызываем функцию
if (rdir ($folder)) {
    echo 'DONE';
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mihalytch.org.ua/programming/php/recursive-reading-files-on-php.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

