I've been working on some code to rename files and have being doing so by copying them to the same location under a different name and then removing the original. When I do this for files I use the code ...
Expand|Select|Wrap|Line Numbers
- Dim file As New System.IO.FileInfo(lstFiles.SelectedItem.ToString)
- Dim strNewFile As String
- Dim strRename As String
- Dim strMask As String = ""
- Dim intCurrentNum As Integer
- Dim cntNumber As Integer
- intCurrentNum += 1
- For cntNumber = 1 To numMask.Text
- If strMask <> "" Then
- strMask = strMask & "0"
- Else
- strMask = "0"
- End If
- Next
- strRename = txtRename.Text & Format(intCurrentNum, strMask)
- strNewFile = file.Directory.ToString & "\" & strRename & file.Extension.ToString
- file.CopyTo(strNewFile)
- file.Delete()
My current code that I'm trying to get to do this looks like:
Expand|Select|Wrap|Line Numbers
- Dim folder As New System.IO.DirectoryInfo(lstFiles.SelectedItem.ToString)
- Dim strNewFile As String
- Dim strRename As String
- Dim strMask As String = ""
- Dim intCurrentNum As Integer
- Dim cntNumber As Integer
- intCurrentNum += 1
- For cntNumber = 1 To numMask.Text
- If strMask <> "" Then
- strMask = strMask & "0"
- Else
- strMask = "0"
- End If
- Next
- strRename = txtRename.Text & Format(intCurrentNum, strMask)
- strNewFile = folder.FullName & "\" & strRename
- MessageBox.Show(strNewFile)
- folder.MoveTo(strNewFile)
- folder.Delete()
If anyone has any suggestions on how to do this they would be greatly appreciated. I'm pretty new to VB.Net coding so you might have to spell things out for me a bit.
Thanks,
Karl