批处理改名字

doudoushen 2006-01-01 01:14:20
我想把一些.JPG文件改成1.JPG 2.JPG~~~ 但是运行一下代码好像老是跳过文件 不知道为什么
单步调试的时候总发现 System.IO.File.Move(f.FullName ,f.DirectoryName+"\\"+num.ToString()+".jpg"); 有时候不能正确改名字

int num=0;
bool aa=true;
DirectoryInfo d=new DirectoryInfo(@"C:\Documents and Settings\Administrator\My Documents\My Pictures");
FileInfo[] files = d.GetFiles("*.jpg");
foreach(FileInfo f in files)
{
if(f.Extension==".jpg")
{
num++;
try
{
Console.Write(f.FullName);
System.IO.File.Move(f.FullName ,f.DirectoryName+"\\"+num.ToString()+".jpg"); }
catch
{
while(aa==true)
{
num++;
if(! System.IO.File.Exists(f.DirectoryName+"\\"+num.ToString()+".jpg") )
aa=false; }
System.IO.File.Move(f.FullName ,f.DirectoryName+"\\"+num.ToString()+".jpg");
aa=true;
}
}
}
}
...全文
85 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxuu503 2006-01-01
  • 打赏
  • 举报
回复
什么样的名字改不了?
doudoushen 2006-01-01
  • 打赏
  • 举报
回复
doudoushen 2006-01-01
  • 打赏
  • 举报
回复
ding

110,536

社区成员

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

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

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