المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : IOException and Number formatting



C# Programming
07-02-2009, 04:10 PM
I'm writing a small program to help me sort my thousands of images.
But whenever I want to rename a file, I get the following error:
The process cannot access the file because it is being used by another process.

I use the following code for itprivate void B_Rename_Click(object sender, EventArgs e)
{
L_Status.Text = "";
File.Move(Path.GetFullPath(images[current]), Path.GetFullPath(TB_New_Name.Text));
L_Status.Text = "image '" + images[current] + "." + extension +
"'\r\nhas been renamed to\r\n'" +
TB_New_Name.Text + "." + extension + "'";
images[current] = TB_New_Name.Text;
}images is the string list holding the file names, current is the current index and extension is the file extension.

My other problem is the number formatting.
The images should be named with numbers, but since windows sorting is strictly text based, 2 would come after 10.
So, I tried the string.Format method to name the images 001, 002, etc., but it doesn't quite work.public F_Main()
{
InitializeComponent();
files = Directory.GetFiles(dir);
this.Text = string.Format("{0:00}", 1);
this.Text += " - ";
this.Text = string.Format("{0:00}", 12);
this.Text += " - ";
this.Text += string.Format("{0:00}", 120);
}I thought this code would display "001 - 012 - 120" in the form title, but instead it onlydisplays "12 - 120"

Thanks.