200分问一简单问题

binbin2000 2003-06-06 02:05:06
怎样修改文件名称。最好给出代码。
http://expert.csdn.net/Expert/topic/1878/1878051.xml?temp=.3798792是我以前开的,如果对了200分。
...全文
27 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
31533586 2003-06-08
  • 打赏
  • 举报
回复
up
ArLi2003 2003-06-08
  • 打赏
  • 举报
回复
补充:

同一目录:改的是FAT 表文件名
同一逻辑盘:改的是FAT 表文件名和偏移位置
源和目标不在同一盘:重写所有内容(理论上来说比复制还慢)
ArLi2003 2003-06-07
  • 打赏
  • 举报
回复
to snewxf(心疤) 俺不是说你,楼上是指上面的,说楼主几位

明明在原贴已经说了用move 这里却非要开贴叫人避开move 用其它方法。。。逼的楼上几位想出各种歪点子,哈哈。。
cangus 2003-06-06
  • 打赏
  • 举报
回复
是否可以用直接访问物理fat表的方式来修改呀,那样做的效率可能要高一点,因为直接跳过了操作系统,只不过对于编程者的要求比较高,更多的是,要是遇到了ntfs格式的分区,好像那方面的资料很少呀,

顺便说一句,谁有ntfs格式的资料一定要放上来哦
dplxp 2003-06-06
  • 打赏
  • 举报
回复
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶
snewxf 2003-06-06
  • 打赏
  • 举报
回复
晕!谢谢提醒。俺真没想到这一层!
ArLi2003 2003-06-06
  • 打赏
  • 举报
回复
楼上的学过FAT 表吗?知道那是什么吗?

呵呵,就是使用 file.move

它操作的源和目标对象如果是同一目录并不是移动而是直接修改分配表中的文件名并不会改动物理偏移,呵呵,你自己用diskmon 或filemon 试试就知道了
snewxf 2003-06-06
  • 打赏
  • 举报
回复
private void button1_Click(object sender, System.EventArgs e)
{
string path = @"D:\test";
string[] spacifyFile=Directory.GetFiles(path);
int i=0;
foreach(string tempFile in spacifyFile)
{

i++;
System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
Info.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden;
Info.FileName = "cmd.exe";
string renameStr = @"/c rename "+tempFile+" "+i.ToString()+"eeee.txt";
Info.Arguments =renameStr;
//Info.RedirectStandardOutput = true;
//Info.UseShellExecute = false;
System.Diagnostics.Process.Start(Info);

}

}
记得加名字空间:using System.Diagnostics;
snewxf 2003-06-06
  • 打赏
  • 举报
回复
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfsystemdirectoryservicesdirectoryentryclassctortopic.htm

它有个DirectoryEntry.Rename 方法试试!
joachern 2003-06-06
  • 打赏
  • 举报
回复
up
qimini 2003-06-06
  • 打赏
  • 举报
回复
我的思路是这样,你看看怎么样

Process proc = new Process();
proc.StartInfo.FileName="ren";
proc.StartInfo.CreateNoWindow=true;
proc.StartInfo.Arguments="xxx.doc yyy.txt";
proc.Start();
binbin2000 2003-06-06
  • 打赏
  • 举报
回复
谢谢 superct(圣堂·天子) :我要重新修改名称的文件大概有80万个,你的代码效率是不是有点低?可行性不好吧。因为我想写一快速重命名的工具。
shuker 2003-06-06
  • 打赏
  • 举报
回复
这是一个方法,但是我想一定有别的办法的,否则如果文件很大的话,这样的效率就。。。。
superct 2003-06-06
  • 打赏
  • 举报
回复
咔咔, 代码帖少了一部分
public Rename(string sourceFile, string destinyFile)
{
if(System.IO.File.Exist(sourceFile))
{
try
{
System.IO.File.Move(sourceFile, destinyFile);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
else
{
Console.WriteLine("源文件{0}不存在!", sourceFile);
}
}
superct 2003-06-06
  • 打赏
  • 举报
回复
public Rename(string sourceFile, string destinyFile)
if(System.IO.File.Exist(sourceFile))
{
try
{
System.IO.File.Move(sourceFile, destinyFile);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
或者先File.Copy(sourceFile, destinyFile);
再File.Delete(sourceFile);
参考ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfsystemiofileclasstopic.htm

111,093

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧