搜索
首页后端开发php教程 php的rename函数用不了,该怎么解决

php的rename函数用不了
//保存为UseFile5_for_rename.php

  $filepath="C:/Users/Administrator/Desktop/新建文件夹/";
  $readarray=file($filepath."分集梗概.txt");
  $sign1="第";
  $sign2="集"; 
  $nameArray=array();
  if(!$readarray){
  echo "用file函数读取文件失败
";
  }  
  else 
  foreach($readarray as $value){
  if(strstr($value,$sign1)&&strstr($value,$sign2))  
  //使用strpos要注意汉字的字节位
  array_push($nameArray,$value);
  //else echo "找不到"; 
  }
  echo sizeof($nameArray)."
";
   
  //按序重命名文件
   
  $i=1;
   
  foreach($nameArray as $value){
  $value=trim($value); //有必要
  echo $value."
";
  $filename=$filepath."(".$i.")".".txt";
  $value=$filepath.$value.".txt";
  rename($filename,$value);
  $i++;
  if($i>10)break; //文件夹内文件的总数
  }
   
  //映射法重命名文件
   
  echo "


";
?>
-------------------------------------------------------运行结果:
86
第1集 洪太尉误走妖魔

Warning: rename((1).txt,第1集 洪太尉误走妖魔.txt) [function.rename]: No error in R:\Program Files\AppServ\www\filetest\UseFile5_for_rename.php on line 30
第2集 石碣村七星聚义

Warning: rename((2).txt,第2集 石碣村七星聚义.txt) [function.rename]: No error in R:\Program Files\AppServ\www\filetest\UseFile5_for_rename.php on line 30
第3集 九纹龙私走延安府

Warning: rename((3).txt,第3集 九纹龙私走延安府.txt) [function.rename]: No error in R:\Program Files\AppServ\www\filetest\UseFile5_for_rename.php on line 30
第4集 鲁提辖拳义助金翠莲

Warning: rename((4).txt,第4集 鲁提辖拳义助金翠莲.txt) [function.rename]: No error in R:\Program Files\AppServ\www\filetest\UseFile5_for_rename.php on line 30
第5集 拳打镇关西

Warning: rename((5).txt,第5集 拳打镇关西.txt) [function.rename]: No error in R:\Program Files\AppServ\www\filetest\UseFile5_for_rename.php on line 30
第6集 鲁达剃度文殊寺

Warning: rename((6).txt,第6集 鲁达剃度文殊寺.txt) [function.rename]: No error in R:\Program Files\AppServ\www\filetest\UseFile5_for_rename.php on line 30
第7集 豹子头误入白虎堂

Warning: rename((7).txt,第7集 豹子头误入白虎堂.txt) [function.rename]: No error in R:\Program Files\AppServ\www\filetest\UseFile5_for_rename.php on line 30
第8集 倒拔垂杨柳

Warning: rename((8).txt,第8集 倒拔垂杨柳.txt) [function.rename]: No error in R:\Program Files\AppServ\www\filetest\UseFile5_for_rename.php on line 30
第9集 大闹野猪林

Warning: rename((9).txt,第9集 大闹野猪林.txt) [function.rename]: No error in R:\Program Files\AppServ\www\filetest\UseFile5_for_rename.php on line 30
第10集 林冲棒打洪教头

Warning: rename((10).txt,第10集 林冲棒打洪教头.txt) [function.rename]: No error in R:\Program Files\AppServ\www\filetest\UseFile5_for_rename.php on line 30
----------------------------

/*
  因为当前路径为UseFile5_for_rename.php文件路径,而我想修改$filepath目录下的10个文件:

  原名为(i).txt (i=1,2,3...,10);

  如果把文件剪切在当前路径下用:

  $filename="(".$i.")".".txt";
  $value=$value.".txt";
  rename($filename,$value);
  可以实现

  那为什么在绝对路径下不可以呢?
*/

------解决方案--------------------
这好像是 php5.3的一个bug,到现在还没更正吗?
------解决方案--------------------
是不是需要权限,没有设置对。不是很清楚,难道是楼上说的?
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
高流量网站的PHP性能调整高流量网站的PHP性能调整May 14, 2025 am 12:13 AM

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

PHP中的依赖注入:初学者的代码示例PHP中的依赖注入:初学者的代码示例May 14, 2025 am 12:08 AM

你应该关心DependencyInjection(DI),因为它能让你的代码更清晰、更易维护。1)DI通过解耦类,使其更模块化,2)提高了测试的便捷性和代码的灵活性,3)使用DI容器可以管理复杂的依赖关系,但要注意性能影响和循环依赖问题,4)最佳实践是依赖于抽象接口,实现松散耦合。

PHP性能:是否可以优化应用程序?PHP性能:是否可以优化应用程序?May 14, 2025 am 12:04 AM

是的,优化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)优化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,并避免使用

PHP性能优化:最终指南PHP性能优化:最终指南May 14, 2025 am 12:02 AM

theKeyStrategiestosiminificallyBoostphpapplicationPermenCeare:1)useOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)优化AtabaseInteractionswithPreparedStateTemtStatementStatementSandProperIndexing,3)配置

PHP依赖注入容器:快速启动PHP依赖注入容器:快速启动May 13, 2025 am 12:11 AM

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增强codemodocultion,可验证性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

PHP中的依赖注入与服务定位器PHP中的依赖注入与服务定位器May 13, 2025 am 12:10 AM

选择DependencyInjection(DI)用于大型应用,ServiceLocator适合小型项目或原型。1)DI通过构造函数注入依赖,提高代码的测试性和模块化。2)ServiceLocator通过中心注册获取服务,方便但可能导致代码耦合度增加。

PHP性能优化策略。PHP性能优化策略。May 13, 2025 am 12:06 AM

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)启用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替换loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

PHP电子邮件验证:确保正确发送电子邮件PHP电子邮件验证:确保正确发送电子邮件May 13, 2025 am 12:06 AM

phpemailvalidation invoLvesthreesteps:1)格式化进行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具