错误我上传我的代码在服务器上的svn文件和文件夹。我无法访问SSH,因此无法运行命令。 所以有没有任何的PHP代码,我可以从我的项目中删除所有.svn文件夹。删除所有.svn文件和文件夹使用php
0
A
回答
0
我在这里得到一个解决方案是
从lateralcode复制几乎不做修改
$path = $_SERVER['DOCUMENT_ROOT'].'/work/remove-svn-php/'; // path of your directory
header('Content-type: text/plain'); // plain text for easy display
// preconditon: $dir ends with a forward slash (/) and is a valid directory
// postcondition: $dir and all it's sub-directories are recursively
// searched through for .svn directories. If a .svn directory is found,
// it is deleted to remove any security holes.
function removeSVN($dir) {
//echo "Searching: $dir\n\t";
$flag = false; // haven't found .svn directory
$svn = $dir . '.svn';
if(is_dir($svn)) {
if(!chmod($svn, 0777))
echo "File permissions could not be changed (this may or may not be a problem--check the statement below).\n\t"; // if the permissions were already 777, this is not a problem
delTree($svn); // remove the .svn directory with a helper function
if(is_dir($svn)) // deleting failed
echo "Failed to delete $svn due to file permissions.";
else
echo "Successfully deleted $svn from the file system.";
$flag = true; // found directory
}
if(!$flag) // no .svn directory
echo 'No .svn directory found.';
echo "\n\n";
$handle = opendir($dir);
while(false !== ($file = readdir($handle))) {
if($file == '.' || $file == '..') // don't get lost by recursively going through the current or top directory
continue;
if(is_dir($dir . $file))
removeSVN($dir . $file . '/'); // apply the SVN removal for sub directories
}
}
// precondition: $dir is a valid directory
// postcondition: $dir and all it's contents are removed
// simple function found at http://www.php.net/manual/en/function.rmdir.php#93836
function delTree($dir) {
$files = glob($dir . '*', GLOB_MARK); // find all files in the directory
foreach($files as $file) {
if(substr($file, -1) == '/')
delTree($file); // recursively apply this to sub directories
else
unlink($file);
}
if (is_dir($dir)){
//echo $dir;
// die;
rmdir($dir); // remove the directory itself (rmdir only removes a directory once it is empty)
}
}
// remove all .svn directories in the
// current directory and sub directories
// (recursively applied)
removeSVN($path);
1
编辑:
找到所有.svn
文件夹是一个复杂的过程,要做到这一点,你需要一个使用递归函数。
链接代码:http://pastebin.com/i5QMGm1C
或视图在这里:
function rrmdir($dir)
{
foreach(glob($dir . '/*') as $path) {
if(is_dir($path)){
rrmdir($path);
}
else{
unlink($path);
}
}
foreach(glob($dir . '/.*') as $path) {
if(is_dir($path)){
$base_name = basename($path);
if ($base_name != '..' && $base_name != '.'){
rrmdir($path);
}
}
else{
unlink($path);
}
}
rmdir($dir);
}
function delete_dir($base, $dir)
{
static $count = 0;
foreach (glob($base . '/*') as $path){
if(is_dir($path)){
delete_dir($path, $dir);
}
}
foreach (glob($base . '/.*') as $path){
if(is_dir($path)){
$base_name = basename($path);
if ($base_name != '..' && $base_name != '.'){
if ($base_name == $dir){
rrmdir($path);
echo 'Directory (' . $path . ') Removed!<br />';
$count++;
}
else {
delete_dir($path, $dir);
}
}
}
}
return $count;
}
$base = $_SERVER['DOCUMENT_ROOT'];
$dir = '.svn';
$count = delete_dir($base, $dir);
echo 'Total: ' . $count . ' Folders Removed!';
相关问题
- 1. SVN文件夹删除
- 2. 删除.svn文件夹
- 3. 使用Delphi递归删除所有文件和文件夹
- 4. 删除所有文件和文件夹,但排除目录
- 5. 删除除了一个文件夹中的所有文件夹/文件和所有根文件
- 6. 删除文件夹和所有子文件夹(包括文件夹)中的所有文件
- 7. 删除除特定文件夹以外的所有文件夹
- 8. 使用Windows注册表删除所有.svn和.project文件
- 9. 删除文件夹内的所有文件,但删除最后?
- 10. 删除所有文件夹中使用PHP
- 11. 使用批次删除除一个文件夹外的所有文件夹
- 12. 从文件夹和所有包含的子文件夹中删除txt文件
- 13. 从某个文件夹中删除所有文件和文件夹
- 14. 删除文件夹和子文件夹中的所有隐藏文件
- 15. Powershell v1 - 删除指定文件夹以外的所有文件和文件夹
- 16. 删除文件夹中的所有文件和文件夹,期望以
- 17. 删除文件夹中的所有文件,排除某些文件被删除
- 18. 从“.svn/pristine”文件夹中删除旧的SVN文件
- 19. 通过Ant FTP任务删除所有文件和文件夹
- 20. 删除FTP连接中的文件夹和所有文件
- 21. 删除所有文件和文件夹连接到FTP
- 22. 如何使用php删除特定文件夹中的所有文件
- 23. .svn文件夹和文件
- 24. PHP - 所有文件和文件夹指定的文件夹
- 25. 如何使用PHP删除文件夹?
- 26. 使用c删除文件夹后删除文件夹#
- 27. 删除父文件夹内的所有文件夹
- 28. 删除文件夹内的所有文件夹?
- 29. 上传到git/svn之前可以删除的所有文件/文件夹
- 30. PHP删除文件到文件夹中
你想删除以.svn结尾的所有文件夹和文件? – rullof
http://d.pr/i/I10m http://d.pr/i/OLmr 请检查下拉列表图片 这个项目是在svn上创建每个文件夹中的.svn文件夹,所以我想删除所有.svn文件夹及其中的所有文件。 – urfusion
它只是一个文件夹吗?还是很多? – rullof