递归设置所有文件和文件夹的权限

编程入门 行业动态 更新时间:2024-10-24 20:15:33
本文介绍了递归设置所有文件和文件夹的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想递归设置文件夹和文件的权限.文件夹应该有750个,文件应该有644个.我发现此并进行了一些修改.这会行吗?

I want to recursively set the folder and file permissions. Folders should get 750 and files 644. I found this and made some adaptions. Would this one work?

<?php function chmod_r($Path) { $dp = opendir($Path); while($File = readdir($dp)) { if($File != "." AND $File != "..") { if(is_dir($File)){ chmod($File, 0750); }else{ chmod($Path."/".$File, 0644); if(is_dir($Path."/".$File)) { chmod_r($Path."/".$File); } } } } closedir($dp); } ?>

推荐答案

为什么不为此使用查找工具?

Why don't use find tool for this?

exec ("find /path/to/folder -type d -exec chmod 0750 {} +"); exec ("find /path/to/folder -type f -exec chmod 0644 {} +");

更多推荐

递归设置所有文件和文件夹的权限

本文发布于:2023-11-12 11:47:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581417.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   文件夹   权限   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!