@@ -219,18 +219,18 @@ Public Class ValidateFolderName
219219 Inherits Validate
220220 Public Property Path As String
221221 Public Property UseMinecraftCharCheck As Boolean = True
222- Public Property IgnoreCase As Boolean = True
223- Private ReadOnly PathIgnore As IEnumerable( Of DirectoryInfo)
224- Public Property IgnoreFolderName As String = Nothing
222+ Private ReadOnly PathDirs As IEnumerable( Of DirectoryInfo) = {}
223+ Public Property OldName As String = Nothing
225224 Public Sub New ()
226225 End Sub
227- Public Sub New (Path As String , Optional UseMinecraftCharCheck As Boolean = True , Optional IgnoreCase As Boolean = True , Optional IgnoreFolderName As String = Nothing )
226+ Public Sub New (Path As String , Optional UseMinecraftCharCheck As Boolean = True , Optional OldName As String = Nothing )
228227 Me .Path = Path
229- Me .IgnoreCase = IgnoreCase
230228 Me .UseMinecraftCharCheck = UseMinecraftCharCheck
231- On Error Resume Next
232- PathIgnore = New DirectoryInfo(Path).EnumerateDirectories
233- Me .IgnoreFolderName = IgnoreFolderName
229+ Try
230+ PathDirs = New DirectoryInfo(Path).EnumerateDirectories
231+ Catch ex As Exception
232+ End Try
233+ Me .OldName = OldName
234234 End Sub
235235 Public Overrides Function Validate(Str As String ) As String
236236 Try
@@ -254,16 +254,17 @@ Public Class ValidateFolderName
254254 '检查 NTFS 8.3 文件名(#4505)
255255 If RegexCheck(Str, ".{2,}~\d" ) Then Return "文件夹名不能包含这一特殊格式!"
256256 '检查文件夹重名
257- Dim Arr As New List( Of String )
258- If PathIgnore IsNot Nothing Then
259- For Each Folder As DirectoryInfo In PathIgnore
260- If IgnoreFolderName Is Nothing OrElse Not Folder.Name.ToLower = IgnoreFolderName.ToLower OrElse Folder.Name = Str Then
261- Arr.Add(Folder.Name)
257+ Dim SameNameCheck = New ValidateExceptSame(PathDirs.Select( Function (di As DirectoryInfo) di.Name).ToArray(), "不可与现有文件夹重名!" , IgnoreCase:= True ).Validate(Str)
258+ If Not SameNameCheck = "" Then
259+ '进行重命名相关的特判
260+ If OldName?.Equals(Str, StringComparison.OrdinalIgnoreCase) Then
261+ If OldName.Equals(Str) Then
262+ Return "请输入一个不同的名称!"
262263 End If
263- Next
264+ Else
265+ Return SameNameCheck
266+ End If
264267 End If
265- Dim SameNameCheck = New ValidateExceptSame(Arr, "不可与现有文件夹重名!" , IgnoreCase).Validate(Str)
266- If Not SameNameCheck = "" Then Return SameNameCheck
267268 Return ""
268269 Catch ex As Exception
269270 Log(ex, "检查文件夹名出错" )
380381 Next
381382 Return ""
382383 End Function
383- End Class
384+ End Class
0 commit comments