- Joined
- Feb 19, 2010
- Messages
- 157
- Reaction score
- 174
Offline
Hey everyone:
I'm trying to rename files to begin with "1" as they are chosen but my 1 has been off. Could someone look at my code and let me know if they notice anything out of place or that's just flat wrong.
Thanks
I'm trying to rename files to begin with "1" as they are chosen but my 1 has been off. Could someone look at my code and let me know if they notice anything out of place or that's just flat wrong.
Thanks
Code:
private void opnBtn_Click(object sender, EventArgs e)
{
string oldPath;
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.InitialDirectory = @"H:\";
fdlg.Filter = "All files (*.*), |*.*";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
oldPath = fdlg.FileName;
string backSlashSch = "\\";
string backSlashPos = oldPath.Substring(0, oldPath.LastIndexOf("\\") + 1);
int backPos = oldPath.LastIndexOf(backSlashSch);
int endOfPath = oldPath.Length;
int calcPos = (endOfPath - backPos - 1);
string newPath = oldPath.Insert(calcPos, "1");
MessageBox.Show(oldPath);
MessageBox.Show(backSlashPos);
MessageBox.Show(backPos.ToString());
MessageBox.Show(endOfPath.ToString());
MessageBox.Show(calcPos.ToString());
MessageBox.Show(newPath);
pathDsp.Text= (oldPath + " " + backSlashPos + " " + backSlashPos + " " + endOfPath + " " + calcPos + " " + newPath);
}
}