用Directory.Move移动文件夹改名是报错路径拒绝访问,但是其他的文件夹可以这样操作
private void GetStarImage(string newFileName, string oldFileName)
{
StreamWriter sw = new StreamWriter(pathFile + "ImageHelp\\mingxingtup\\" + newFileName + ".txt", false, Encoding.GetEncoding("GBK"));
string fullPath = pathFile + "xml\\pic\\" + oldFileName;
if (!Directory.Exists(fullPath)) fullPath = pathFile + "xml\\pic\\" +newFileName;
string[] allOldFolder = Directory.GetDirectories(fullPath);
int i = 1;
foreach (string oldFolder in allOldFolder)
{
ModifyFileName(new DirectoryInfo(oldFolder+"\\240x320"));//先改文件名
string[] allOldFile = Directory.GetFiles(oldFolder + "\\240x320");
foreach (string oldFile in allOldFile)
{
string fileName = TakeFileName(oldFile);
if (fileName.Substring(fileName.Length - 1) != "r")
{
if (checkFile(oldFile))
{
ThumbnailImage(oldFile, oldFile.Substring(0, oldFile.LastIndexOf(".")) + "r.dat");//如果图片没有缩放,就进行缩放
}
}
}
//文件夹改名
string folderName =Regex.Replace(oldFolder.Substring(oldFolder.LastIndexOf("\\") + 1),"\\d","");
sw.Write(folderName + "-" + newFileName + i);//宠物趣图-chongwuqutu1
string newfolder = fullPath + "\\" + newFileName + i;//新文件名
if (!Directory.Exists(newfolder))//文件不存在替换
{
Directory.Move(oldFolder, newfolder);//替换文件夹
}
i++;
}
sw.Close();
sw.Dispose();
if (!Directory.Exists(pathFile + "xml\\pic\\" + newFileName)) Directory.Move(fullPath, pathFile + "xml\\pic\\" + newFileName);
}