|
楼主 |
发表于 2005-12-9 13:34:52
|
显示全部楼层
下面这个可以了吧。
Imports System.IO
public module ChangeNames
sub Main
Dim strDirToChange As String, intPrefix As Integer, strEnd As String
Console.Write("Directories to Change: ")
strDirToChange = Console.ReadLine
Console.Write("# of Prefix to Change: ")
intPrefix = cInt(Console.ReadLine)
If Not Directory.Exists(strDirToChange) Then
Console.Write("Please check the directory path.")
strEnd = Console.ReadLine
Exit Sub
End If
If intPrefix < 1 Then
Console.Write("Please check Prefix you want to change.")
strEnd = Console.ReadLine
Exit Sub
End If
Dim strSubDir1, strSubDir2, strNewName, strPrefix, strMain As String
Dim intIndex As Integer
On Error Resume Next
For Each strSubDir1 In Directory.GetDirectories(strDirToChange)
For Each strSubDir2 In Directory.GetDirectories(strSubDir1)
intIndex = strSubDir2.LastIndexOf("\")
strMain = Mid(strSubDir2, intIndex + 2 + intPrefix + 1, strSubDir2.Length)
strPrefix = Mid(strSubDir2, intIndex + 2, intPrefix)
strNewName = strMain & "_" & strPrefix
Directory.Move(strSubDir2, strSubDir1 & "\" & strNewName)
Next
Next
Console.Write("All the directories have been successfully renamed.")
strEnd = Console.ReadLine
end sub
end module |
|