Ali G

Ali G

  • NA
  • 51
  • 38.5k

Want to Rename All Files But Getting Exception

Sep 27 2013 7:16 PM
I have this code but it gives IOException. What is the problem with "File.Move(files[i].FullName, newFileWithPath);"  line?

==================================================
        private void button1_Click(object sender, System.EventArgs e)
        {
            DialogResult result = folderBrowserDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                string pathname = @folderBrowserDialog1.SelectedPath;
                FileInfo[] files = new DirectoryInfo(pathname).GetFiles("*.JPG");
                for (int i = 0; i < files.Length; i++)
                {
                    string newFile = String.Format("{0}{1}.{2}", "A", (i+1), "JPG");
                    string fullNewPath = files[i].DirectoryName;
                    string newFileWithPath = Path.Combine(fullNewPath, newFile);
                    File.Move(files[i].FullName, newFileWithPath);
                }



            }

        }
==================================================

Answers (5)